BookmarkSubscribeRSS Feed
excelsas
Calcite | Level 5
I have written a macro to split a large dataset into several states datasets but getting an error message for OR (Oregon) state as it is a boolean operator but working fine for NE(Nebraska) state.
I tried %quote but it did not work.


%quote(&state)=%str(OR)

Any suggestion would be appreciated.

Also I used Proc format and value to change the values of a variable in the main datasets but the values are unchanged in the states datasets.
What should I use to change the values permanently?


Thanks,
3 REPLIES 3
Ksharp
Super User
Have you used %superq() ?



Ksharp
DBailey
Lapis Lazuli | Level 10
Within macros, I often have to use the double quote like this:

"&State."="OR"

I know there are sometimes issues with the variables have extraneous characters, but if the domain is known, this might work.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
%quote(...) with %str(..) works -- also a technique I sometimes use is to simply append a period/dot character in the expression to remove the resemblence of a Boolean operator, such as shown below.

Scott Barry
SBBWorks, Inc.


%macro x(state);
%if %quote(&state) = %str(OR) %then %put yep;
%else %put nope;
%Mend x;
%x(NE);

%macro x(state);
%if .&state = .OR %then %put yep;
%else %put nope;
%Mend x;
%x(OR);

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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