Hello SAS world,
I need your help with the following:
Have:
PatientID Date
X 01/22/2012
X 01/30/2012
X 01/31/2012
X 02/02/2012
Want:
PatientID Date Diff
X 01/22/2012 0
X 01/30/2012 8
X 01/31/2012 1
X 02/02/2012 2
Thanks in advance!
Here is one way:
data want; set have; by PatientID; diff=ifn(first.PatientID eq 0,dif(date),0); run;
Art, CEO, AnalystFinder.com
Here is one way:
data want; set have; by PatientID; diff=ifn(first.PatientID eq 0,dif(date),0); run;
Art, CEO, AnalystFinder.com
Hello,
Thanks for the earlier help, I need your help to solve the next problem.
From the previous output I got the difference between dates. In the study period, I want to flag patients where there is difference of >120 days and mark all the dates after that >120 days. If there is a patients who have 2 rows of >120 days then I want to mark first >120 days to the 2nd >120 days as "R1" and "R2" for dates greater than 2nd >120 days.
Thanks!
You will get more responses if you post your new question as a new question .. not a continuation of the previous question.
Art, CEO, AnalystFinder.com
another way
option missing=0;
data have;
input PatientID $ Date :mmddyy10.;
lagdate=intck('day',lag(date),date);
format date date9.;
cards;
X 01/22/2012
X 01/30/2012
X 01/31/2012
X 02/02/2012
;
You will need a line to reset the calculated difference to zero for the first obs in an ID group. Something like this:
option missing=0;
data have;
input PatientID $ Date :mmddyy10.;
lagdate=intck('day',lag(date),date);
if PatientID ne lag(PatientID) then lagdate = 0;
format date date9.;
cards;
X 01/22/2012
X 01/30/2012
X 01/31/2012
X 02/02/2012
y 01/22/2017
y 01/30/2017
y 01/31/2017
y 02/02/2017
;
run;
Hi ... OPTIONS MISSING=0 does NOT change values of missing data in a data set to ZERO. It only changes the way they appear when printed.
1169
1170 options missing=0;
1171 data x;
1172 x = 1;
1173 y = .;
1174 z = x + y;
1175 run;
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line) : (Column).
1 at 1174:7
If you print data set X you see ZEROES (due to the OPTIONS statement), but if you look at the LOG, you'll notice that SAS still sees MISSING data.
From online help (notice that it says printed)...
Syntax
MISSING=<'>character<'>
Syntax Description
<'>character<'>
specifies the value to be printed. The value can be any character. Single or double quotation marks are optional. The period is the default.
Thank you!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.