BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
abhinayingole
Obsidian | Level 7


%macro chk (result = );
data one;
val = "&result.";
run;
%mend chk;

%chk (result = %str(Intensity (%)) );

 

I need to print result for VAL variable  as "Intensity (%)"    ,e.g VAL = "Intensity(%)"   , but not able to do it with above code.

any suggestion please.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

When you use %STR(), you can mask a % with a %, so use %%.  See the docs: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0pnc7p9n4h6g5n16g6js048nhfl.htm

 

Example Log:

1    %macro chk (result = );
2    data one;
3    val = "&result.";
4    put val= ;
5    run;
6    %mend chk;
7
8    %chk (result = %str(Intensity (%%)) );

val=Intensity (%)
NOTE: The data set WORK.ONE has 1 observations and 1 variables.
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

2 REPLIES 2
Quentin
Super User

When you use %STR(), you can mask a % with a %, so use %%.  See the docs: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0pnc7p9n4h6g5n16g6js048nhfl.htm

 

Example Log:

1    %macro chk (result = );
2    data one;
3    val = "&result.";
4    put val= ;
5    run;
6    %mend chk;
7
8    %chk (result = %str(Intensity (%%)) );

val=Intensity (%)
NOTE: The data set WORK.ONE has 1 observations and 1 variables.
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Quentin
Super User

For this example, you don't actually need any macro quoting, you could just use:

8    %chk (result = Intensity (%) )

val=Intensity (%)
NOTE: The data set WORK.ONE has 1 observations and 1 variables.
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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
  • 421 views
  • 2 likes
  • 2 in conversation