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

Hi all, I have a dataset that looks like this. I want to transpose it with the SBP_FU values for each month as the variables by ID, but also retain the first and last followup dates. I was able to do the first or last Follow up date using COPY, but not both. .thanks for your help!

Obs SBP_FU FU_DATE month ID1234567etc.. 
12709/25/20076328
14212/19/20079328
12904/02/200812328
12206/25/200815328
11709/03/200818328
11409/26/20066514
12012/25/20069514
    

The final dataset should look like this ;

ObsIDfirstdatelast dateSBP_6_mnthSBP_9_mnthSBP_12_mnthSBP_15_mnthSBP_18_mnth
13289/25/20079/3/2008127142129122117
25149/26/200612/25/2006114120...
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input SBP_FU FU_DATE :mmddyy10. month ID;
format  FU_DATE mmddyy10. ;
cards;
127	09/25/2007	6	328
142	12/19/2007	9	328
129	04/02/2008	12	328
122	06/25/2008	15	328
117	09/03/2008	18	328
114	09/26/2006	6	514
120	12/25/2006	9	514
;

proc transpose data=have out=w(drop=_:) prefix=SBP_ suffix=_mnth;
by id;
var SBP_FU;
id month;
run;

data want;
if 0 then set have(keep=id FU_DATE) ;
format firstdate  lastdate mmddyy10.;
do until(last.id);
merge have(keep=id FU_DATE) w;
by id;
if first.id then firstdate=FU_DATE;
end;
lastdate=FU_DATE;
drop FU_DATE;
run;

View solution in original post

3 REPLIES 3
r_behata
Barite | Level 11
data have;
input SBP_FU FU_DATE :anydtdte10. month ID $;
cards;
127 09/25/2007 6 328
142 12/19/2007 9 328
129 04/02/2008 12 328
122 06/25/2008 15 328
117 09/03/2008 18 328
114 09/26/2006 6 514
120 12/25/2006 9 514
run;


proc sort data=have;
	by id FU_DATE;
run;


data want;
	format FU_DATE firstdate lastdate date9.;
	array sbp_arr[*] sbp1-sbp5;

	do i=1 to dim(sbp_arr) until(last.id);
		set have;
		by id;

		if first.id then
			firstdate=FU_DATE;
			sbp_arr[i] =SBP_FU;
	end;

	lastdate=FU_DATE;

	drop FU_DATE i month SBP_FU;
run;
novinosrin
Tourmaline | Level 20
data have;
input SBP_FU FU_DATE :mmddyy10. month ID;
format  FU_DATE mmddyy10. ;
cards;
127	09/25/2007	6	328
142	12/19/2007	9	328
129	04/02/2008	12	328
122	06/25/2008	15	328
117	09/03/2008	18	328
114	09/26/2006	6	514
120	12/25/2006	9	514
;

proc transpose data=have out=w(drop=_:) prefix=SBP_ suffix=_mnth;
by id;
var SBP_FU;
id month;
run;

data want;
if 0 then set have(keep=id FU_DATE) ;
format firstdate  lastdate mmddyy10.;
do until(last.id);
merge have(keep=id FU_DATE) w;
by id;
if first.id then firstdate=FU_DATE;
end;
lastdate=FU_DATE;
drop FU_DATE;
run;
rj438
Calcite | Level 5
this worked perfectly, thanks!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 4275 views
  • 2 likes
  • 3 in conversation