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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.