Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Criteria within a SAS where clause 3

Status
Not open for further replies.

JM3482

Technical User
Nov 7, 2003
17
0
0
US
I need to add date criteria to a where clause and I am having no luck. Below is what I have created so far.

DATA FILE;
FORMAT DTE mmddyy8.;
DTE=TODAY();
Date1= put(Today()-4, date9.);
Date2= put(Today()-7, date9.);
RUN;
DATA _NULL_;
SET FILE;
CALL SYMPUT('Newdate', Date1);
CALL SYMPUT('Newdate1',Date2);

I then add the 'Newdate' to my where clause such as below:

where eff_end_dt = &newdate

I use the DTE in another portion of my code. I am using Date1 and Date2 with newdate and newdate1

What could I be doing wrong.
 
I think macro variables are always character data, so you need to convert it back to a numeric field before comparing it to another date.

Try changing your Where clause to something like:

where eff_end_dt = input("&newdate",date9.);

Hope this helps.
 
JM3482,

Call symput is not resolved until after the RUN statement. In other words your newdate macro var does not exist until the next datastep.
While macro vars are character, in the statement above after the macro vars resolve that shouldn't be an issue.

Hope that this helps you.
Klaz
 
Try using this statement instead.

where dte = "&newdate"d;

the 'd' tells sas it's getting a date format and converts it to a SAS date, (I take it that eff_end_dt is a sas date?). This will also allow you to use < or > comparators.

Hope that helps. A useful debugging tip is to put in put statements to show what the values you are looking at actually look like (watch out for applied formats though). In this case you are comparing a sas date (a number like 16082) to a formatted text string like &quot;14JAN2003&quot;, which obviously won't work.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top