BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anita_n
Pyrite | Level 9

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?

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Kurt_Bremser
Super User

You use the wrong "by" variable, see this:

proc transpose data=test out=test_trans (drop=_name_);
id type;
var stage;
by year;
run;
Anita_n
Pyrite | Level 9

Thanks a lot it worked fine

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 529 views
  • 0 likes
  • 2 in conversation