Hi i have an array called disch (*) disch1-disch9.
I have a second array with empty values called dis_new(*) disch_new1-disch_new9.
disch_new takes on the value of disch if its value is after the disch prior. However, if the disch value is before, then i want disch_new to take on the prior. Therefore, dischnew1-6 are the same as disch1-6. However, dischnew7-dischnew9 all become 26June18:10:00:00.
I am not having any luck with the way I have it set up. If anyone can help that will be great.
Current code is this:
ARRAY DIS(*) DISCH1 - DISCH&IDY;
ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&IDY.;
DIS_NEW[1]=DIS[1];
DIS_NEW[2]=DIS[2];
/* If discharge date ends prior to previous discharge*/
DO I=2 TO DIM(DIS_NEW);
IF DIS_NEW[I]<DIS[I-1] THEN DIS_NEW[I]=DIS[I-1];
ELSe DIS_NEW[I]=DIS[I];
END;
Like this?
do I = 1 to DIM(DIS_NEW);
DIS_NEW[I] = max( DIS_NEW[I-1], DIS[I] );
end;
I believe for a DISCH_NEW<n> variable to never have a value lower than DISCH_NEW<n-1> the code @ChrisNZ posted needs a tweak. Below should do the job.
%let IDY=11;
data have;
input DISCH1 - DISCH&IDY;
datalines;
1 2 1 1 3 4 2 2 2 4 5
;
data want;
set have;
ARRAY DIS(*) DISCH1 - DISCH&IDY;
ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&IDY.;
DIS_NEW[1]=DIS[1];
/* If discharge date ends prior to previous discharge*/
DO I=2 TO DIM(DIS_NEW);
IF DIS[I]<DIS_NEW[I-1] THEN
DIS_NEW[I]=DIS_NEW[I-1];
ELSe DIS_NEW[I]=DIS[I];
END;
run;
proc print data=want;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.