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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 777 views
  • 0 likes
  • 2 in conversation