BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Spintu
Quartz | Level 8
proc transpose data=test out=want (drop=_:) prefix=o_;
var o_value;
by subject crs;
id var;
run.
subjectcrsvarvalueo_value
1010thresp  
101998threspNENE
101998threspPDPD

 

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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.
Spintu
Quartz | Level 8

I am looking for ALL of the observations in the output.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 1347 views
  • 1 like
  • 2 in conversation