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 have a list of accounts and their customer Ids, some accounts can have more than 1 customer and different customer types.  I would like to transpose by type of customer.  Here's what I mean:

 

HAVE

Acct      Type_A     Type_B     Type_C

001          123            234      

001          123            356 

002          567            124           345

002          567            124           678

 

WANT

Acct     Type_A       Type_B1       Type_B2       Type_C1       Type_C2

001         123               234                  356              

002         567               124                                          345              678

 

This logic applied to a list of 1 million accouts.

 

thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @podarum  Assuming I understand the req.

 

data have;
infile cards truncover;
input Acct   $   Type_A     Type_B     Type_C;
cards;
001          123            234      
001          123            356 
002          567            124           345
002          567            124           678
;
data temp;
 set have;
 by acct;
 if first.acct then grp=0;
 grp+1;
 array t type_:;
 do over t;
  vn=vname(t);
  v=t;
  output;
 end;
 drop type_:;
run;

proc sort data=temp out=temp2 nodupkey;
by acct vn v;
run;

proc transpose data=temp2 out=want(drop=_:);
by acct;
id vn grp;
var v;
run;

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @podarum  Assuming I understand the req.

 

data have;
infile cards truncover;
input Acct   $   Type_A     Type_B     Type_C;
cards;
001          123            234      
001          123            356 
002          567            124           345
002          567            124           678
;
data temp;
 set have;
 by acct;
 if first.acct then grp=0;
 grp+1;
 array t type_:;
 do over t;
  vn=vname(t);
  v=t;
  output;
 end;
 drop type_:;
run;

proc sort data=temp out=temp2 nodupkey;
by acct vn v;
run;

proc transpose data=temp2 out=want(drop=_:);
by acct;
id vn grp;
var v;
run;

 

podarum
Quartz | Level 8

You Rock.. Thank You !!!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 801 views
  • 1 like
  • 2 in conversation