BookmarkSubscribeRSS Feed
Raj00007
Calcite | Level 5

i am a basic SAS learner. how to use where statement, when the variable it self as a where.

 

data task1;
set sasuser.Acities;
run;

data task2;
set task1;
where 'Country where Aiport is located' = 'USA';
run;

2 REPLIES 2
Kurt_Bremser
Super User

A variable is a variable is a variable, not "a where".

 

The most simple WHERE condition is usually a comparison of a variable with a literal value, like

where country = 'USA';

Your code also does not need the first data step, you can reference sasuser.acities directly in the second step.

PaigeMiller
Diamond | Level 26

As written, your comparison of 

 

where 'Country where Aiport is located' = 'USA';

will always fail because the text string 'Country where Aiport is located' is never equal to the text string 'USA'

 

I think what you might want is a variable name instead of the text string 'Country where Aiport is located', but only you know what that variable name would be. I use "variablename" as the variable name, of course you would use the actual variable name.

 

Like this:

 

data task1;
set sasuser.Acities;
where variablename = 'USA';
run;

 

 

 

--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 373 views
  • 1 like
  • 3 in conversation