BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cm3
Fluorite | Level 6 cm3
Fluorite | Level 6
Data _null_;
Call symput (‘currdt’,put(datetime(),datetime20.));
Call symput(“prvdt’,put(datetime()-5,datetime20.));
Run;
%put &currdt.;
%put &prvdt.;

Prvdt is not returning expected result, please advise.
Thank you
1 ACCEPTED SOLUTION

Accepted Solutions
AhmedAl_Attar
Ammonite | Level 13

Hi @cm3 

Try this 

Data _null_;
	currdt = datetime();
	Call symput ('currdt',put(currdt,datetime20.));
	prvdt = intnx('dtday',currdt,-5,'same');
	Call symput('prvdt',put(prvdt,datetime20.));
Run;

View solution in original post

4 REPLIES 4
AhmedAl_Attar
Ammonite | Level 13

Hi @cm3 

Try this 

Data _null_;
	currdt = datetime();
	Call symput ('currdt',put(currdt,datetime20.));
	prvdt = intnx('dtday',currdt,-5,'same');
	Call symput('prvdt',put(prvdt,datetime20.));
Run;
cm3
Fluorite | Level 6 cm3
Fluorite | Level 6
It worked. Thank you Sir.
sbxkoenk
SAS Super FREQ

You go back 5 seconds.

 

Here's correct code:

data _null_;
a=datetime();
b=INTNX('DTDAY',a,-5,'SAME');
*format a b datetime20.;
Call symputx('currdt',put(a,datetime20.));
Call symputx('prvdt' ,put(b,datetime20.));
Run;
%put &=currdt.;
%put &=prvdt.;
/* end of program*/

Koen

ballardw
Super User

The function you want would be INTNX. Subtracting 5 just gets you 5 seconds earlier.

 

If you want to shift a datetime value by days what should happen with the Time portion of the value? Your choices would be the Beginning of the day, the Same time of day or the End of the day

The INTNX function first parameter is an interval. When you want to shift a datetime value by day (or week, month, year ) use DT before the interval to let SAS know that the expected input value is a Datetime

 

Data _null_;
Call symputx ('currdt',put(datetime(),datetime20.));
Call symputx ('prvdtB',put(intnx('dtday',datetime(),-5,'B'),datetime20.));
Call symputx ('prvdtS',put(intnx('dtday',datetime(),-5,'S'),datetime20.));
Call symputx ('prvdtE',put(intnx('dtday',datetime(),-5,'E'),datetime20.));
Run;

%put &prvdtB. &prvdtS. &prvdtE. ;

Note that the code you posted does not run because somewhere along the line it picked up "smart quotes", the curly looking ones. They are not usable in SAS code. Plus a mismatch of double and single. It is best to post code into a text box opened on the forum with the </> as the forum software will reformat some text pasted into the main windows.

 

Note use of SYMPUTX function instead of Symput. Symputx will remove leading and trailing spaces that otherwise frequently appear in conversions like this.

 

 


@cm3 wrote:
Data _null_;
Call symput (currdt,put(datetime(),datetime20.));
Call symput(prvdt,put(datetime()-5,datetime20.));
Run;
%put &currdt.;
%put &prvdt.;

Prvdt is not returning expected result, please advise.
Thank you

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 892 views
  • 0 likes
  • 4 in conversation