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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 523 views
  • 1 like
  • 3 in conversation