Hi,
I have data regarding when patients enrolled in study from 01/01/1992 to 12/31/2019. I am trying to put these patients into 4 groups like this below:
DATA dtanl.hivcancerdta_enrlgrp;
set dtanl.hivcancerdta;
format lastdate date9.;
enrolldt = DATEPART (lastdate);
IF enrolldt = . THEN enrlgrp = .;
ELSE IF '01JAN1992'D <= enrolldt < '01JAN1998'D THEN enrlgrp = 1;
ELSE IF '01JAN1998'D <= enrolldt < '01JAN2004'D THEN enrlgrp = 2;
ELSE IF '01JAN2004'D <= enrolldt < '01JAN2010'D THEN enrlgrp = 3;
ELSE IF enrolldt >= '01JAN2010'D THEN enrlgrp = 4;
RUN;
When doing this, the variable enrolldt fills as 0 and enrlgrp fills as missing.
I was having trouble with this and looked at other SAS community threads detailing similar issues but no matter what I tried it isnt working. Any help would be appreciated.
Thanks!
DATEPART is to convert SAS datime values to SAS date values. I suspect that lastdate is already a SAS date value. Try replacing
enrolldt = DATEPART (lastdate);
with
enrolldt = lastdate;
DATEPART is to convert SAS datime values to SAS date values. I suspect that lastdate is already a SAS date value. Try replacing
enrolldt = DATEPART (lastdate);
with
enrolldt = lastdate;
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.