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