Hello,
I would like to transpose a table.
I only want one the same value in ID.
Thanks a lot for your help.
TABLE | ||||||
ID | CODE | DATE | ||||
01 | FAZ58 | 07/01/2020 | ||||
01 | FZE78 | 04/01/2020 | ||||
02 | DS52 | 05/01/2020 | ||||
02 | YU89 | 04/01/2020 | ||||
02 | LM69 | 04/01/2020 | ||||
03 | DS24 | 05/01/2020 | ||||
04 | FS24 | 06/01/2020 | ||||
04 | XC89 | 07/01/2020 | ||||
WANT: | ||||||
ID | CODE1 | DATE1 | CODE2 | DATE2 | CODE3 | DATE3 |
01 | FAZ58 | 07/01/2020 | FZE78 | 04/01/2020 | ||
02 | DS52 | 05/01/2020 | YU89 | 04/01/2020 | LM69 | 04/01/2020 |
03 | DS24 | 05/01/2020 | ||||
04 | FS24 | 06/01/2020 | XC89 | 07/01/2020 |
data have;
input ID $ CODE $ DATE :ddmmyy10.;
format date ddmmyy10.;
cards;
01 FAZ58 07/01/2020
01 FZE78 04/01/2020
02 DS52 05/01/2020
02 YU89 04/01/2020
02 LM69 04/01/2020
03 DS24 05/01/2020
04 FS24 06/01/2020
04 XC89 07/01/2020
;
proc sql noprint;
select max(obs) into :obs
from ( select count(*) as obs from have group by id ) ;
quit;
proc summary nway data=have missing;
class id ;
output out = want(drop=_type_ _freq_)
idgroup(out[&obs](code date)=);
run;
Why do you want to do this? 🙂
data have;
input ID $ CODE $ DATE :ddmmyy10.;
format date ddmmyy10.;
cards;
01 FAZ58 07/01/2020
01 FZE78 04/01/2020
02 DS52 05/01/2020
02 YU89 04/01/2020
02 LM69 04/01/2020
03 DS24 05/01/2020
04 FS24 06/01/2020
04 XC89 07/01/2020
;
proc sql noprint;
select max(obs) into :obs
from ( select count(*) as obs from have group by id ) ;
quit;
proc summary nway data=have missing;
class id ;
output out = want(drop=_type_ _freq_)
idgroup(out[&obs](code date)=);
run;
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!
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.