BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mindmeld
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Spacetime
Obsidian | Level 7

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.

View solution in original post

6 REPLIES 6
ballardw
Super User

Some one may be trying to get if the city is not blank.

mindmeld
Calcite | Level 5

That seems to be the case.  So is &city ne  equivalent to:  &city ne .  ?

Thanks

Spacetime
Obsidian | Level 7

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.

Spacetime
Obsidian | Level 7

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.

data_null__
Jade | Level 19

NE is the comparision operator and it means NOT EQUAL.  In both expressions.

Jay_TxOAG
Quartz | Level 8

I like to use

%if &city ne %str() %then %do;

instead of leaving a blank space...just because it is more obvious to me

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
  • 6 replies
  • 39373 views
  • 3 likes
  • 5 in conversation