|
How DATA step works? DATA step processes the file in an iterative way. It behaves and acts like a loop and the SAS System executes it on every observation (or record), one at a time. After an observation is processed and/or outputted, the system goes back to the top of the DATA step loop and begin to execute on the next record. On every iteration the DATA step variables find missing values as the initial values, except for special variables such as _N_, _ERROR_, _I_, _CMC_, _MSG_, and options as IN= and END= of a SET, MERGE, or UPDATE statement. These values will not be carried over from previous observations, instead the values will be deleted. These observations are treated independently. However, we can establish a link between observations using the RETAIN statement and LAG function.
The RETAIN statement is used to hold the value of 1 in variable FLAG. It keeps its value as long as we do not alter it. In the later IF condition statement we modify the value of variable FLAG. Whereas the LAG function is to carry over the variable ENDDATE (Service Date) enable us to calculate the DAYS between end date and previous date.
|
data gcm2.testcases;
set gcm2.cases;
where type='INPATIENT';
SASDate=input(put(srvbgdt,z8.),yymmdd8.);
run;
proc sort data=gcm2.testcases;
by memberid srvbgdt;
run;
|
data gcm2.testcases;
set gcm2.testcases;
by memberid;
retain Flag 1;
EndDate=sasdate+los;
PrevDate=lag(enddate);
if first.memberid
then prevdate=sasdate;
Flag=1;
Days=enddate-prevdate;
if sasdate ne prevdate
then do;
if days<2 then flag=0;
end;
run;
|
|