DATA Step, Macro, Functions and more

Macro issue and how to permanently change values of a variable?

Reply
Occasional Contributor
Posts: 8

Macro issue and how to permanently change values of a variable?

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,
Super User
Posts: 10,018

Re: Macro issue and how to permanently change values of a variable?

Have you used %superq() ?



Ksharp
Super Contributor
Posts: 578

Re: Macro issue and how to permanently change values of a variable?

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Macro issue and how to permanently change values of a variable?

%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);
Ask a Question
Discussion stats
  • 3 replies
  • 142 views
  • 0 likes
  • 4 in conversation