BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

I came across a situation where I used macro variables  in my pgm created by using macro function %str. I got error. when I  removed %str function I did not get error. Please help me understand. Thank you

 

I created 4 macro variables. Two using %str function. Other two not. When I run  %one macro using macro variables created using %str function. I am getting error. But when i run with other two, I am not. Please help.

%let gm_ba                       = %str(03)                                                              ;
%let gm_snum                     = %str(a0310)                                                      ;
%let gm_ca                       = 03                                                              ;
%let gm_tnum                     = a0310                                                           ;
data aaa;
input a $ b;
datalines;
a 1 
b 2
c 3
;
%macro one;
data c&gm_ba&gm_snum.01;
set aaa;
run;
%mend;
%one;
%macro one; data c&gm_ca&gm_tnum.01; set aaa; run; %mend;
%one;
2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Always look at the log.

 

You'll see that quoting the macro variable using %str()  adds non-printable characters.

 

Use the %unquote() function in your data step.

yabwon
Amethyst | Level 16

Reading this article: https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf will help you understand secrets of macro quoting.

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 950 views
  • 4 likes
  • 3 in conversation