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