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
Onyx | Level 15

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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