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

I've created the following variable:

 

%let mnth_strt_date_d = %sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, B )), date9.));

 

I want to use mnth_strt_date_d as a date filter for a SAS table, but in order to so I need the value to be '01MAY19'd.  Right now it is coming back as 01MAY19.  How can I add the single quotes and d to mnth_strt_date_d?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You likely don't. 

 

If you remove the date9 format, it will likely work with your code:

 

%let mnth_strt_date_d = %sysfunc(intnx(month, %sysfunc(today()), -1, B ));

You also don't need PUT here, the second parameter for the SYSFUNC() is the format you'd like applied to the output.

 

If you really do think you need it, I'd actually put in the code to resolve correctly, this way the macro variable is more versatile. 

 

So change wherever you're using the macro variable to the following, note the usage of double quotes.

 

"&mnth_strt_date_d."d

@Yozshura wrote:

I've created the following variable:

 

%let mnth_strt_date_d = %sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, B )), date9.));

 

I want to use mnth_strt_date_d as a date filter for a SAS table, but in order to so I need the value to be '01MAY19'd.  Right now it is coming back as 01MAY19.  How can I add the single quotes and d to mnth_strt_date_d?

 

Thank you!


 

View solution in original post

2 REPLIES 2
Reeza
Super User

You likely don't. 

 

If you remove the date9 format, it will likely work with your code:

 

%let mnth_strt_date_d = %sysfunc(intnx(month, %sysfunc(today()), -1, B ));

You also don't need PUT here, the second parameter for the SYSFUNC() is the format you'd like applied to the output.

 

If you really do think you need it, I'd actually put in the code to resolve correctly, this way the macro variable is more versatile. 

 

So change wherever you're using the macro variable to the following, note the usage of double quotes.

 

"&mnth_strt_date_d."d

@Yozshura wrote:

I've created the following variable:

 

%let mnth_strt_date_d = %sysfunc(putn(%sysfunc(intnx(month, %sysfunc(today()), -1, B )), date9.));

 

I want to use mnth_strt_date_d as a date filter for a SAS table, but in order to so I need the value to be '01MAY19'd.  Right now it is coming back as 01MAY19.  How can I add the single quotes and d to mnth_strt_date_d?

 

Thank you!


 

Yozshura
Calcite | Level 5
Yep, that worked. Thank you so much!

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 880 views
  • 0 likes
  • 2 in conversation