Hi,
am tring to transpose a dataset:
data test;
infile datalines;
input class $ type $ year sex stage
datalines;
a12 event1 0 2 100
a12 event2 0 2 100
a12 event3 0 2 100
a12 event4 0 2 100
a12 unkn 0 2 100
a12 event1 1 2 95
a12 event2 1 2 92
a12 event3 1 2 48
a12 event4 1 2 91
a12 unkn 1 2 100
a12 event1 2 2 94
a12 event2 2 2 80
a12 event3 2 2 55
a12 event4 2 2 23
a12 unkn 2 2 50
a12 event1 3 2 77
a12 event2 3 2 69
a12 event3 3 2 80
a12 event4 3 2 90
a12 unkn 3 2 88
a12 event1 4 2 99
a12 event2 4 2 36
a12 event3 4 2 57
a12 event4 4 2 94
a12 unkn 4 2 60
a12 event1 5 2 69
a12 event2 5 2 47
a12 event3 5 2 52
a12 event4 5 2 76
a12 unkn 5 2 98
;
run;
at the end I wish to get an output that looks like this: (the attached excel data)
I tried using this code
proc transpose data=test out=test_trans;
id type;
var stage;
by type;
run;
this was giving a warning that the "id value is twice by the same group" so I added "let" at the end of proc transpose.
This is not giving me the desired output. It only gives me the last values of each type.
please any help?
You use the wrong "by" variable, see this:
proc transpose data=test out=test_trans (drop=_name_);
id type;
var stage;
by year;
run;
You use the wrong "by" variable, see this:
proc transpose data=test out=test_trans (drop=_name_);
id type;
var stage;
by year;
run;
Thanks a lot it worked fine
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.