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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

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;

PG
pramenon1
Obsidian | Level 7
Thank you so much for your quick reply! This worked perfectly!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 422 views
  • 1 like
  • 2 in conversation