BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
data long;
	input enrolid1 date1 : mmddyy10. test result location;
	format date1 mmddyy10.;
	datalines;
4 5/5/2009    blood  65  inp
4 5/5/2009    colon   Y   inp
4 5/5/2009    stomach Y inp 
4 5/6/2009    head     N  inp
4 5/6/2009    blood  55 out
4 5/6/2009    colon  N  out
4 5/6/2009   stomach N out 
4 5/6/2009   neck     Y out 
4 5/6/2009   ZY       Y out 
5 5/5/2009   blood 55 inp 
5 5/5/2009   add Y inp 
5/5/5/2009   mst N inp;
run;

I have the above data, I need to transpose it to a wide format by listing each "test" for that specific date. Variable location is fixed for each patient during a specific date.

Output I am looking for 

enrolid1 date1 blood colon stomach head neck ZY add mst  location 

4   5/5/2009   65       Y          Y            .       .        .      .      .      inp 

4    5/6/2009  55       N          N          N     Y      Y       .     .       out                         

5     5/5/2009 55       .            .           .       .        .      Y     N      inp 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data long;
	input enrolid1 date1 : mmddyy10. test $ result $ location $;
	format date1 mmddyy10.;
	datalines;
4 5/5/2009    blood  65  inp
4 5/5/2009    colon   Y   inp
4 5/5/2009    stomach Y inp 
4 5/6/2009    head     N  inp
4 5/6/2009    blood  55 out
4 5/6/2009    colon  N  out
4 5/6/2009   stomach N out 
4 5/6/2009   neck     Y out 
4 5/6/2009   ZY       Y out 
5 5/5/2009   blood 55 inp 
5 5/5/2009   add Y inp 
5 5/5/2009   mst N inp
;
run;
proc transpose data=long out=long_t;
    by enrolid1 date1;
	id test;
	var result location;
run;
data want;
	merge long_t(where=(_name_='result')) 
		long_t(where=(_name_='location') keep=enrolid1 date1 _name_ blood 
        rename=(blood=location));
    by enrolid1 date1;
	drop _name_;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data long;
	input enrolid1 date1 : mmddyy10. test $ result $ location $;
	format date1 mmddyy10.;
	datalines;
4 5/5/2009    blood  65  inp
4 5/5/2009    colon   Y   inp
4 5/5/2009    stomach Y inp 
4 5/6/2009    head     N  inp
4 5/6/2009    blood  55 out
4 5/6/2009    colon  N  out
4 5/6/2009   stomach N out 
4 5/6/2009   neck     Y out 
4 5/6/2009   ZY       Y out 
5 5/5/2009   blood 55 inp 
5 5/5/2009   add Y inp 
5 5/5/2009   mst N inp
;
run;
proc transpose data=long out=long_t;
    by enrolid1 date1;
	id test;
	var result location;
run;
data want;
	merge long_t(where=(_name_='result')) 
		long_t(where=(_name_='location') keep=enrolid1 date1 _name_ blood 
        rename=(blood=location));
    by enrolid1 date1;
	drop _name_;
run;
--
Paige Miller
lillymaginta
Lapis Lazuli | Level 10

Thank you Piage! very helpful! 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 546 views
  • 1 like
  • 2 in conversation