If/then for between dates

Occasional Contributor
Posts: 7

If/then for between dates

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!

Regular Contributor
Posts: 217

Re: If/then for between dates

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.

Super User
Posts: 13,583

Re: If/then for between dates

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.

Occasional Contributor
Posts: 7

Re: If/then for between dates

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!

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation