BookmarkSubscribeRSS Feed
ILeskow
Calcite | Level 5
Hi, I am trying to do the following to pass in the system date and subtract the date so the StartDate will read 09MAR2009 and the EndDate will be 15MAR2009. I'm not sure if I am doing this correctly. This will allow me to run the code automatically instead of hard coding a date each time. Any help is appreciated!


%LET StartDate =%sysfunc(intnx(week.2, "&SYSDATE"D, 0), DATE9.);
%LET EndDate =%sysfunc(intnx(week.7, "&SYSDATE"D, 0), DATE9.);

PROC SQL;
CREATE TABLE TD_Mature AS
SELECT distinct t.contract_no AS Matured_TD
FROM ptware.term_deposits t
WHERE t.mature_date between '&StartDate' and '&EndDate'
AND t.cease_date is not null
AND t.mature_date = t.cease_date;
quit;
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Setting OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MLOGIC; would likely help reveal SAS behavior when using your macro variables in your PROC SQL code. The macro variable string, when coded within single quote marks, will not be resolved, as compared to coding the macro variable string inside double-quote marks -- this is a SAS standard feature.

Scott Barry
SBBWorks, Inc.

SAS DOC links from the SAS support website http://support.sas com/

Introduction to Macro Variables
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293823.htm


Displaying Macro Variable Values
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001071910.htm


SAS Conference Paper on the topic:

Add SAS® Macros to Your Programming Skills: Achieve More, Write Less Code
Peter Crawford, Crawford Software Consultancy Ltd, UK
http://www2.sas.com/proceedings/forum2008/175-2008.pdf
LinusH
Tourmaline | Level 20
I'm not sure what kind of interval you are trying to create, but if you intend to always have Monday to Sunday in the current week, I think you misunderstood the use of the week.X interval. I think that you should stick with week.2, and use the BEGINNING and END with the intnx function:

%LET StartDate =%sysfunc(intnx(week.2, "&SYSDATE"D, 0, beginning), DATE9.);
%LET EndDate =%sysfunc(intnx(week.2, "&SYSDATE"D, 0, end), DATE9.);
%put &startdate &enddate;
09MAR2009 15MAR2009

/Linus
Data never sleeps

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 626 views
  • 0 likes
  • 3 in conversation