BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Daily1
Quartz | Level 8
/* Sample data */
data have;
input ID $ TYPE $ TYPE_ID;
datalines;
1 A 1
1 B 1
1 c 1
1 d 1
1 e 1
1 f 1
1 g 2
1 h 2
1 j 2
1 k 2
1 l 2
1 q 3
1 w 3
1 e 3
1 r 3
1 t 3
1 y 4
1 u 4
1 i 4
;
run;
Desired Output
ID    1       2       3        4
1     A        g        q        y
1     B        h        w        u
1     c        j        e        i
1     d        k        r
1     e        l        t
1     f

i need to transpose data

proc transpose data=haveout=youroutput prefix=ID_;
  by ID;
  var TYPE;
  id TYPE_ID;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data pretrans;
set have;
by id type_id;
if first.type_id
then group = 1;
else group + 1;
run;

proc sort data=pretrans;
by id group;
run;

proc transpose
  data=pretrans
  out=want
;
by id group;
var type;
if type_id;
run;

as you can't have multiple identical ID (the statement!) values within a BY group of PROC TRANSPOSE, so you must create a new group for this.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
data pretrans;
set have;
by id type_id;
if first.type_id
then group = 1;
else group + 1;
run;

proc sort data=pretrans;
by id group;
run;

proc transpose
  data=pretrans
  out=want
;
by id group;
var type;
if type_id;
run;

as you can't have multiple identical ID (the statement!) values within a BY group of PROC TRANSPOSE, so you must create a new group for this.

Ksharp
Super User
/*Just for having some fun*/
data have;
input ID $ TYPE $ TYPE_ID;
datalines;
1 A 1
1 B 1
1 c 1
1 d 1
1 e 1
1 f 1
1 g 2
1 h 2
1 j 2
1 k 2
1 l 2
1 q 3
1 w 3
1 e 3
1 r 3
1 t 3
1 y 4
1 u 4
1 i 4
;
run;
proc sql noprint;
select distinct catt('have(where=(TYPE_ID=',TYPE_ID,') rename=(type=_',TYPE_ID,'))')
      into :merge separated by ' '
 from have;
quit;
data want;
 merge &merge.;
 by id;
 output;
 call missing(of _all_);
 drop TYPE_ID;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1158 views
  • 0 likes
  • 3 in conversation