BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I currently have the following:

proc sql;
select
a.id,
b.logon_id,
b.enter_date,
b.cd,
b.bef_desc,
b.aft_desc
from
fs.ROOT_VIEW a,
fs.t_trans b
where
a.id=b.id and
enter_date between to_date(07/01/2010,mm/dd/yyyy') and to_date(07/01/2010,mm/dd/yyyy') ;

I want to write a macro so that when this runs monthly, I won't have to physically change the date range. I'm not sure how to go about this since it's a Proc SQL. Any suggesstions?
3 REPLIES 3
Peter_C
Rhodochrosite | Level 12
I don't think "to_date(07/01/2010,mm/dd/yyyy') " is base SAS syntax. You might use something like that in "explicit pass-through sql" subject to the sql flavor of the underlying dbms.
SAS becomes simpler if you can use "implicit pass-through sql queries". Then your date filter clause can be just [pre] and enter_date between "&from_date"d and "&to_date"d[/pre] where macro variables &from_date and &to_date are filled in base SAS code to look like 10Aug2010 and 21Jul2010.
The handling of implicit-pass-through syntax by PROC SQL will re-present SAS date constants in the query that is passed to the dbms so that they are in the style that that dbms needs.

sorry it is sounding convoluted - but that is the way it seems (to me).

peterC
deleted_user
Not applicable
good done
thank you
PatrickG
SAS Employee
Lots of good info on using SAS dates here. Hopefully, this will help.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002200738.htm

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1145 views
  • 0 likes
  • 3 in conversation