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
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;
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;
Thank you r_behata its works.
Can the 2 "data _null_ " merged on one step?
Thanks,
Hi,
Macro variables enclosed in single quotes will not be resolved. You have to always use double quotes only.
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.