Hi, basic question.
I understand this:
%if &city ne 'New York' %then %do;
* do stuff here
%end;
but not this:
%if &city ne %then %do;
* do stuff here
%end;
What does the 'ne' mean in the second statement? Is it comparing &city ne to...what exactly?
Thanks
Nope. The &city ne . would be true whenever the macro variable does not resolve to exactly = .
The &city ne would be true whenever the macro variable does not resolve to exactly = (nothing at all).
Keep in mind that macro variables are literal text strings, so when it checks for ne and nothing after, it is literally checking for nothing in the string.
I think it compares it to a missing value for the macro variable.
So when I %let city = something,
it triggers that '&city ne is true'.
But when
%let city=;
You get '&city ne is false'.
So it must test against an empty macro variable by default.
Kind of a cool behavior, I only learned it from experimenting with your code.
Some one may be trying to get if the city is not blank.
That seems to be the case. So is &city ne equivalent to: &city ne . ?
Thanks
Nope. The &city ne . would be true whenever the macro variable does not resolve to exactly = .
The &city ne would be true whenever the macro variable does not resolve to exactly = (nothing at all).
Keep in mind that macro variables are literal text strings, so when it checks for ne and nothing after, it is literally checking for nothing in the string.
I think it compares it to a missing value for the macro variable.
So when I %let city = something,
it triggers that '&city ne is true'.
But when
%let city=;
You get '&city ne is false'.
So it must test against an empty macro variable by default.
Kind of a cool behavior, I only learned it from experimenting with your code.
I think it compares it to a missing value for the macro variable.
So when I %let city = something,
it triggers that '&city ne is true'.
But when
%let city=;
You get '&city ne is false'.
So it must test against an empty macro variable by default.
Kind of a cool behavior, I only learned it from experimenting with your code.
NE is the comparision operator and it means NOT EQUAL. In both expressions.
I like to use
%if &city ne %str() %then %do;
instead of leaving a blank space...just because it is more obvious to me
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: