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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.