j*******i 发帖数: 97 | 1 can I get some help?
I have a dataset.
obs v1 v2 v3 f1
1 4 5 6 1
2 2 3 9 3
3 2 5 7 2
column f1 indicates the variable version to use.
for exmaple, first row, f1=1, then we need to use the value of v1 (output
the value: 4)
second row, f1=3, then we need to use the value of v3 (output
the value: 9)
and so on...
the output result needs to be a sas dataset that contains all the outputs;
What's the most efficient way to create the output?
Thank you very much.
sorry. cannot type Chinese for now. | w****r 发帖数: 28 | | j*******i 发帖数: 97 | 3 can you elaborate a little bit?
Dumping v1-v3 as an array?
doable but does not seem to be efficient in terms of storage.
【在 w****r 的大作中提到】 : array…
| a****g 发帖数: 8131 | 4 %let a = f1
in a macro, have the following
v = v&a; output;
this should work
【在 j*******i 的大作中提到】 : can I get some help? : I have a dataset. : obs v1 v2 v3 f1 : 1 4 5 6 1 : 2 2 3 9 3 : 3 2 5 7 2 : column f1 indicates the variable version to use. : for exmaple, first row, f1=1, then we need to use the value of v1 (output : the value: 4) : second row, f1=3, then we need to use the value of v3 (output
| k*****u 发帖数: 45 | 5 刚学macro和sql不久,想了个笨办法,lz找到了更好的办法的话不要笑我。。。
data a;
input v1 v2 v3 f1;
datalines;
4 5 6 1
2 3 9 3
2 5 7 2
;
run;
%macro test;
proc sql;
alter table a
add v num
;
%do i=1 %to 3;
update a
set v=v&i
where a.f1=&i
;
%end;
quit;
%mend;
%test;
【在 j*******i 的大作中提到】 : can I get some help? : I have a dataset. : obs v1 v2 v3 f1 : 1 4 5 6 1 : 2 2 3 9 3 : 3 2 5 7 2 : column f1 indicates the variable version to use. : for exmaple, first row, f1=1, then we need to use the value of v1 (output : the value: 4) : second row, f1=3, then we need to use the value of v3 (output
| w****r 发帖数: 28 | 6 data a;
input v1 v2 v3 f1;
datalines;
4 5 6 1
2 3 9 3
2 5 7 2
run;
data b;
set a;
array v[1:3] v1-v3;
newvalue = v[f1];
run; | j*******i 发帖数: 97 | 7 this one works. I will send you BaoZi.
thanks.
【在 w****r 的大作中提到】 : data a; : input v1 v2 v3 f1; : datalines; : 4 5 6 1 : 2 3 9 3 : 2 5 7 2 : run; : data b; : set a; : array v[1:3] v1-v3;
|
|