Good morning,
I've been an SPSS user for a very long time and I now have to learn how to use SAS. I am having trouble creating a flag variable of enrolled based on dates.
I have the following data set:
id entry_date leave_date leave_code
1 2015-09-01 2016-07-01 L
2 2013-08-27 9999-12-31 N
3 2014-11-19 2015-02-28 L
4 2013-12-31 2016-09-15 T
I'm trying to do a 1 or 0, 1 indicating still enrolled. Basically if the leave date is eq 9999-12-31 student is still enrolled if the leave_date is gt 2016-06-30 then the student is still enrolled.
Any help on this would be greatly appreciated!
Good catch Sir @Tom Most embarrassing moment to not think that 31DEC9999 is also greater than 30JUN2016 . What a shame I caused to myself lol, Cheers though! 🙂
data have;
input id (entry_date leave_date ) (:yymmdd10.) leave_code $;
format entry_date leave_date yymmdd10.;
cards;
1 2015-09-01 2016-07-01 L
2 2013-08-27 9999-12-31 N
3 2014-11-19 2015-02-28 L
4 2013-12-31 2016-09-15 T
;
data want;
set have;
Flag=leave_date eq '31dec9999'd or leave_date gt '30jun2016'd;
run;
Hey, everything will depend on how formatted are your variables. Could you show us how they are?
What did you try? The result of a boolean expression is going to be either 1 (true) or 0 (false);
31DEC9999 is also greater than 30JUN2016 so you probably just need one test.
data want;
set have;
flag = leave_date > '30JUN2016'd;
run;
Good catch Sir @Tom Most embarrassing moment to not think that 31DEC9999 is also greater than 30JUN2016 . What a shame I caused to myself lol, Cheers though! 🙂
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.