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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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