BookmarkSubscribeRSS Feed
avatar
Fluorite | Level 6


Hello,

I would like to bring data 10 days older from the start date.

I have created a macro for start date shown below.

%let start_dt = '01APR2014'd ;

% let old_dt = %eval(%input(&start_dt ,8.)  -  10);

this gives erro

4 REPLIES 4
ChrisHemedinger
Community Manager

Dates are just numbers, so the easy thing to do is to ensure you seed your %EVAL expression with them as numbers using SAS functions.

Examples:

/* 10 days before today */
%let cutoff = %eval(%sysfunc(today()) - 10);

/* 10 days before April 1, 2014 */
%let cutoff = %eval(%sysfunc(mdy(4,1,2014)) - 10);

Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
user24feb
Barite | Level 11

%LET old_dt=%Sysfunc(PutN(%Sysfunc(IntNX(day,&start_dt.,-10)),Date9.));

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, few things there.  The start_dt macro variable will contain the text '01APR2014'd

when this resovles on the eval you will get: %let old_dt = %eval(%input('01APR2014'd ,8.)  -  10);

This will fail as there is a d after the quote.  Also, you have a space between the % and let.  

I would question why you need to do this as:

data _null_;

     call symput('OLD_DT','01APR2014'd - 10);

run;

would give the result, plus several other methods of getting there.

avatar
Fluorite | Level 6

Chris example seems simple to use. I will try that.

thanks all

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1835 views
  • 3 likes
  • 4 in conversation