proc transpose data=test out=want (drop=_:) prefix=o_;
var o_value;
by subject crs;
id var;
run.
subject | crs | var | value | o_value |
101 | 0 | thresp | ||
101 | 998 | thresp | NE | NE |
101 | 998 | thresp | PD | PD |
here I have attached the code and sample data. However, I am getting the below error messages.
ERROR: The ID value "o_tlresp" occurs twice in the same BY group.
can someone help me to fix this?
Sure. What output do you WANT to get in that situation?
Do you want just the FIRST (or LAST) value in the group? If so then first get rid of the unwanted observations.
data for_transpose;
set test;
by subject crs var;
if first.var;
run;
proc transpose data=for_transpose out=want (drop=_:) prefix=o_;
var o_value;
by subject crs;
id var;
run.
Do you want ALL of the observations? Then you need to add a new variable.
data for_transpose;
set test;
by subject crs var;
if first.var then row=0;
row+1;
run;
Do you want them to become new OBSERVATIONS? Then include the new variable in the BY statement.
proc transpose data=for_transpose out=want (drop=_:) prefix=o_;
var o_value;
by subject crs row;
id var;
run.
Do you want them to become new VARIABLES? Then include the new variable in the ID statement.
proc transpose data=for_transpose out=want (drop=_:) prefix=o_;
var o_value;
by subject crs;
id var row;
run.
Sure. What output do you WANT to get in that situation?
Do you want just the FIRST (or LAST) value in the group? If so then first get rid of the unwanted observations.
data for_transpose;
set test;
by subject crs var;
if first.var;
run;
proc transpose data=for_transpose out=want (drop=_:) prefix=o_;
var o_value;
by subject crs;
id var;
run.
Do you want ALL of the observations? Then you need to add a new variable.
data for_transpose;
set test;
by subject crs var;
if first.var then row=0;
row+1;
run;
Do you want them to become new OBSERVATIONS? Then include the new variable in the BY statement.
proc transpose data=for_transpose out=want (drop=_:) prefix=o_;
var o_value;
by subject crs row;
id var;
run.
Do you want them to become new VARIABLES? Then include the new variable in the ID statement.
proc transpose data=for_transpose out=want (drop=_:) prefix=o_;
var o_value;
by subject crs;
id var row;
run.
I am looking for ALL of the observations in the output.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.