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!

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!

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
  • 568 views
  • 0 likes
  • 2 in conversation