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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 937 views
  • 5 likes
  • 5 in conversation