z**********i 发帖数: 12276 | 1 I have two datasets.
1.
ID variablename
001 question1
005 question1
009 question1
002 question2
003 question2
........
2.
ID question1 question2 question3 ...
001 2 1 1
002 2 2 2
003 1 1 2
....
how could get the number from dataset2 to fill in the value of variablename
in dataset1?
I want to get the dataset like
ID variablename
001 2
005 1
Thanks!!!!
|
g*******y 发帖数: 380 | 2 data one;
input ID $ question $9.;
datalines;
001 question1
005 question1
009 question1
002 question2
003 question2
;run;
data two;
input ID $ question1 question2 question3;
datalines;
001 2 1 1
002 2 2 2
003 1 1 2
;
run;
proc sort data=two;
by ID;
run;
proc transpose data=two out=three name=question;
by ID;
run;
proc sql;
create table final as
select one.*, col1 from one, three
where one.ID=three.ID and one.question=three.question;
quit; |
z**********i 发帖数: 12276 | 3 Thanks a million.
【在 g*******y 的大作中提到】 : data one; : input ID $ question $9.; : datalines; : 001 question1 : 005 question1 : 009 question1 : 002 question2 : 003 question2 : ;run; : data two;
|
q**j 发帖数: 10612 | 4 look up PROC TRANSPOSE. I strongly suspect this one can give you the shortes
t, maybe, fastest codes. and you do not need data one at all.
proc transpose data = data2 out = data2;
by id;
run;
you might or might not need other stuff like 'id' statement.
【在 z**********i 的大作中提到】 : Thanks a million.
|