06-10-2014 11:25 AM
i have a dataset with dates formatted as: mmddyy10.
I am trying to create a series of dummy variables based off dates ranges. For instance:
if pur_date >='01JUL2008'd and <='30JUN2009'd then dummy1 = 1.
However, this is not working well. can anyone recommend a better approach to search for data between two dates with the if/then clause/
thanks a lot!
06-10-2014 11:50 AM
if (pur_date >='01JUL2008'd) and (pur_date <='30JUN2009'd) then dummy1 = 1 should work if your pur_date is a SAS date. The format or informat does not matter since SAS dates are stored as numbers.
06-10-2014 12:52 PM
if '01JUL2008'd le pur_date le '30JUN2009'd then dummy=1; /* which will also be easier to read*/
your orginal code would need 'and pur_date <= ' for consistent evaluation.
06-10-2014 01:02 PM
thanks all. that was a typo on my part, as i forgot the second pur_date when I wrote the question above.
I kept getting syntax errors, but it looked fine. thankfully, after restarting my sas project and rerunning my data set, the same code i posted worked. so, all good. but thanks again!