BookmarkSubscribeRSS Feed
bkv1
Calcite | Level 5

Rusty coder here ...

 

I have a data set with the dates from either 2005 or 2015 (format is YYMMDD10.). They all are currently under 1 variable: dovcug 

 

I want to create 2 cohorts of subjects based on the time period they are from, the variable called "cohort" with 0 = all dates from 2005 and 1 = all dates from 2015. This is my code:

 

if dovcug < 2006-01-01 then Cohort = 0;
else if dovcug > 2014-12-31 then Cohort = 1;

run;

 

But when I run proc freq on "Cohort" I only get:

cohort = 1

Frequency = 517

 

No cohort = 0

 

What am doing incorrectly???

3 REPLIES 3
novinosrin
Tourmaline | Level 20

do you not need a sas date constant like this?

 

if dovcug < '01jan2006'd then Cohort = 0;
else if dovcug > '31dec2014'd then Cohort = 1;

bkv1
Calcite | Level 5

That worked. Thank you!

Reeza
Super User

if year(dovcug) = 2005 then cohort=0;

else if year(dovcug)=2015 then cohort=1;

 

If your logic is the year, use the YEAR() 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 336 views
  • 0 likes
  • 3 in conversation