BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nihal
Fluorite | Level 6


Hello,

 

I'd like to build a new variable based on a new existing macro variable &simuldate how has a format date9.

The new variable should be the business day of the last month and has a datetime format .

 

I've tried the code below

 

 

data _null_;
call symputx('datdt',put(intnx('WEEKDAY', intnx('MONTH', &simuldate, -1, 'END'), 0),DATE9.));
run;

 

 this works

But when tried to convert the date in datetime format:

data _null_;
call symputx('datdt_m', put(dhms('&datdt'D,0,0,0),datetime.));
run;

I got
ERROR: Invalid date/time/datetime constant '&datdt'D.


can anyone help.

Thank you

Nihal

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11

Hope this helps :

 

data _null_;
	datdt=intnx('WEEKDAY', intnx('MONTH', &simuldate, -1, 'END'), 0);
	call symputx('datdt_m', put(dhms(datdt,0,0,0),datetime.));
run;

%put &=datdt_m;

View solution in original post

4 REPLIES 4
r_behata
Barite | Level 11

Enclose the macro variable in double quote :

 

data _null_;
call symputx('datdt_m', put(dhms("&datdt"d,0,0,0),datetime.));
run;

%put &=datdt_m;
Nihal
Fluorite | Level 6

Thank you r_behata its works. 

 

Can the 2 "data _null_ " merged on one step?

 

Thanks,

SuryaKiran
Meteorite | Level 14

Hi,

 

Macro variables enclosed in single quotes will not be resolved. You have to always use double quotes only.

Thanks,
Suryakiran
r_behata
Barite | Level 11

Hope this helps :

 

data _null_;
	datdt=intnx('WEEKDAY', intnx('MONTH', &simuldate, -1, 'END'), 0);
	call symputx('datdt_m', put(dhms(datdt,0,0,0),datetime.));
run;

%put &=datdt_m;

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

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
  • 2193 views
  • 1 like
  • 3 in conversation