BookmarkSubscribeRSS Feed
cca8380
Calcite | Level 5

How can I accomplish the following:
%put &q_start_date --> resolves to 01MAR2022
what I need the variable to resolve to is '01MAR2022'

Can anyone help me with the issue.

 

Thanks in advance!

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Better to apply the quotes when the macro variable is used, rather than include the quotes in the macro variable value. So when the macro variable is used, for example in a DATA step, you can do something like this

 

if date > "&q_start_date"d then ... ;

 

If that's not what you are looking for, please be more specific about how this macro variable will be used.

--
Paige Miller
Reeza
Super User
How are you creating the macro variable? Usually fixing it in that step is preferable. And why are single quotes needed? Double quotes will allow a macro variable to resolve correctly.
Tom
Super User Tom
Super User

If you can use double quotes (as you should be able to in normal SAS code) then just use:

%put "&q_start_date";

If you need the single quotes use %bquote().

%put %bquote('&q_start_date');

If the macro quoting added by %BQUOTE() causes trouble remove it.

%put %unquote(%bquote('&q_start_date'));
Kurt_Bremser
Super User

How do you intend to use the macro variable? If you need it for comparisons or calculations, store the raw date value. See Maxim 28.

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
  • 567 views
  • 5 likes
  • 5 in conversation