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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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! 🙂

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
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; 
FelipeMosquetta
Calcite | Level 5

Hey, everything will depend on how formatted are your variables. Could you show us how they are?

Tom
Super User Tom
Super User

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;
novinosrin
Tourmaline | Level 20

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! 🙂

SAS Innovate 2025: Register Now

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!

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
  • 4 replies
  • 2105 views
  • 0 likes
  • 4 in conversation