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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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