标题: 运用format,把数据集b的值代替数据集a的值 [打印本页] 作者: shiyiming 时间: 2011-1-7 23:35 标题: 运用format,把数据集b的值代替数据集a的值 有两个数据集,假设为数据集a的值为
a
3
2
5
,
数据集b的值为
b
1
2
3
请问如何运用format,把数据集b的值代替数据集a的值,想得到的效果类似以下过程:
proc format;
value lbl
3=1
2=2
5=3
;作者: shiyiming 时间: 2011-1-8 01:47 标题: Re: 运用format,把数据集b的值代替数据集a的值 [code:3ekcqvym]proc format;
value lbl
3=1 2=2 5=3
;
==
proc format;
value lbl
3='1' 2='2' 5='3'
;[/code:3ekcqvym]
无论外表如何,这两个format是等价的。
[code:3ekcqvym]data _null_;
x =1;
xx =put(x, lbl.)+0;
x = put(x, lbl.);
run;[/code:3ekcqvym][color=#0000FF:3ekcqvym]NOTE: Character values have been converted to numeric
values。。。
NOTE: Character values have been converted to numeric
values[/color:3ekcqvym]
你的问题或许取决于如何建立format。作者: shiyiming 时间: 2011-1-8 10:51 标题: Re: 运用format,把数据集b的值代替数据集a的值 谢谢啦!可能我对问题的说明不清楚,我是想用数据集a作为format的value左边的值,数据集作为format的value右边的值。因为我实际数据集中的数据很多,不想在proc format中逐个输入设定,所以想类似问题那样,用数据集b对数据集a进行format。作者: shiyiming 时间: 2011-1-8 21:35 标题: Re: 运用format,把数据集b的值代替数据集a的值 不想一个一个的输,那就用宏,但得看实际的对应情况
另外"用数据集b对数据集a进行format"这句话没看懂,你的意思是a中的a和b中的b的取值就是format每行的对应的关系吧,然后是用在c中的比如x变量的format吧..作者: shiyiming 时间: 2011-1-10 11:00 标题: Re: 运用format,把数据集b的值代替数据集a的值 我感觉你还是没有清晰地表述你的问题。
你当然可以用数据集建立format;作者: shiyiming 时间: 2011-1-12 00:02 标题: Re: 运用format,把数据集b的值代替数据集a的值 data one;
input a;
cards;
3
2
5
;
run;
data two;
input b;
cards;
1
2
3
;
run;
data fmtds;
merge one two;
rename a=start b=label;
end=a;
fmtname='newfmt';
run;
proc format library=work cntlin=fmtds;
run;
data test;
input x;
y=put(x,newfmt.);
cards;
3
4
5
6
2
;
run;作者: shiyiming 时间: 2011-1-12 00:06 标题: Re: 运用format,把数据集b的值代替数据集a的值 if you just want to use values from one dataset to replace the values from the other dataset;
data result;
merge one two (rename=(b=a));
run;作者: shiyiming 时间: 2011-1-14 21:18 标题: Re: 运用format,把数据集b的值代替数据集a的值 多谢各位啦!sun59338 的结果是我想要的。