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
Rhodochrosite | Level 12

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
Rhodochrosite | Level 12

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 518 views
  • 0 likes
  • 4 in conversation