BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
podarum
Quartz | Level 8

Hi,  I'm trying to get the proc transpose with a duplicate value ... wanting it to show in the columns.. Here's what I mean:

HAVE;

Acct    ID    Type

234    123   BOR

245    122   BOR

245    124   COB

245    125   COB

245    126   POA

246    128   BOR

246    127   POA

 

WANT

Acct   BOR    COB1    COB2       POA

234    123 

245    122        124         125          126

246    128                                       127

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Acct ID Type $;
datalines;
234 123 BOR
245 122 BOR
245 124 COB
245 125 COB
245 126 POA
246 128 BOR
246 127 POA
;

data temp;
   do _N_ = 1 by 1 until (last.Type);
      set have;
      by Acct Type;
      if not (first.Type and last.Type) then t = cats(Type, _N_);
      else t = Type;
      output;
   end;
run;

proc transpose data = temp out = want(drop=_:);
   by Acct;
   id t;
   var ID;
run;

 

 

Result:

 

Acct  BOR  COB1  COB2  POA 
234   123  .     .     . 
245   122  124   125   126 
246   128  .     .     127 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @podarum  You need an intermediate step to get the sequence and then it's straight forward-



data have;
input Acct    ID    Type $;
cards;
234    123   BOR

245    122   BOR

245    124   COB

245    125   COB

245    126   POA

246    128   BOR

246    127   POA
;

data temp/view=temp;
 set have;
 by acct type;
 if first.type then n=1;
 else n+1;
run;


proc transpose data=temp out=want(drop=_:);
 by acct;
 var id;
 id type n;
run;

 

Acct BOR1 COB1 COB2 POA1
234 123 . . .
245 122 124 125 126
246 128 . . 127
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Acct ID Type $;
datalines;
234 123 BOR
245 122 BOR
245 124 COB
245 125 COB
245 126 POA
246 128 BOR
246 127 POA
;

data temp;
   do _N_ = 1 by 1 until (last.Type);
      set have;
      by Acct Type;
      if not (first.Type and last.Type) then t = cats(Type, _N_);
      else t = Type;
      output;
   end;
run;

proc transpose data = temp out = want(drop=_:);
   by Acct;
   id t;
   var ID;
run;

 

 

Result:

 

Acct  BOR  COB1  COB2  POA 
234   123  .     .     . 
245   122  124   125   126 
246   128  .     .     127 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2431 views
  • 2 likes
  • 3 in conversation