Reputation: 47
I´m trying to extract different variables out of one variable. It will become clear if you look at my data:
data test;
input customer date id volume;
1 1 abc 500
1 2 abc 600
1 2 xyz 200
1 3 xyz 300
2 1 def 400
2 2 def 500
My goal is to create different variables for each id so that the dataset looks like this:
customer date id volume id_abc id_xyz id_def
1 1 abc 500 500 . .
1 2 abc 600 600 . .
1 2 xyz 200 . 200 .
1 3 xyz 300 . 300 .
2 1 def . . 400
2 2 def . . 500
I tried to solve this with proc transpose, but since there is more than one id per customer (I use the option let) SAS drops values. I would be very happy if someone could help!
Upvotes: 2
Views: 93
Reputation: 63424
by
statement and id
statement to get the labels correct.
data test;
input customer date id $ volume;
idvar = cats("id_",id);
datalines;
1 1 abc 500
1 2 abc 600
1 2 xyz 200
1 3 xyz 300
2 1 def 400
2 2 def 500
;;;;
run;
proc transpose data=test out=want ;
by customer date id;
var id;
id idvar;
run;
Upvotes: 1