SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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