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

Hello,

 

I am pretty new to this community but reaching out for help to unravel the difficulty I am having. 

The sample data set is....

data have;
	input ID epi_1 : mmddyy10. epi_2 : mmddyy10. epi_3 : mmddyy10. ;
	format epi_1 mmddyy10. epi_2 mmddyy10. epi_3 mmddyy10.;
	datalines;
	1 01/01/2019 02/01/2019 .
	1 03/01/2019 .          .
	2 04/01/2019 .          .
	2 05/01/2019 .          .
	2 06/01/2019 07/01/2019 .
;
run;

I am trying to transpose the data set by ID but I only want to keep non missing columns and change the column name in sequence (the column name of the first episode should be epi_1).

 

Below is the data set I want to output: 

Capture.PNG

 

Any suggestions are welcome! Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hello @_MooMoo  Welcome to SAS communities as it's your 1st post.

 

See if this helps

 

data have;
	input ID epi_1 : mmddyy10. epi_2 : mmddyy10. epi_3 : mmddyy10. ;
	format epi_1 mmddyy10. epi_2 mmddyy10. epi_3 mmddyy10.;
	datalines;
	1 01/01/2019 02/01/2019 .
	1 03/01/2019 .          .
	2 04/01/2019 .          .
	2 05/01/2019 .          .
	2 06/01/2019 07/01/2019 .
;
run;

proc transpose data=have out=t(where=(col1 ne .) keep=id col1);
by id ep:;
var ep:	;
run;

proc transpose data=t out=want(drop=_:) prefix=Ep_;
by id ;
var col1;
run;

Kind Regards!

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hello @_MooMoo  Welcome to SAS communities as it's your 1st post.

 

See if this helps

 

data have;
	input ID epi_1 : mmddyy10. epi_2 : mmddyy10. epi_3 : mmddyy10. ;
	format epi_1 mmddyy10. epi_2 mmddyy10. epi_3 mmddyy10.;
	datalines;
	1 01/01/2019 02/01/2019 .
	1 03/01/2019 .          .
	2 04/01/2019 .          .
	2 05/01/2019 .          .
	2 06/01/2019 07/01/2019 .
;
run;

proc transpose data=have out=t(where=(col1 ne .) keep=id col1);
by id ep:;
var ep:	;
run;

proc transpose data=t out=want(drop=_:) prefix=Ep_;
by id ;
var col1;
run;

Kind Regards!

_MooMoo
Obsidian | Level 7
Thanks! Didn't think this way.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1288 views
  • 0 likes
  • 2 in conversation