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;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 498 views
  • 0 likes
  • 3 in conversation