Where statement is not working in SAS

sas
proc_sql

#1

Hi, I have YTD data set having variables Month and Sales in SAS:

Month Sales
Jan 12
Feb 13
Mar 14

I want to create a data set where profit is greater than 3 (where Profit = 0.25*Sales) based on YTD. I have written the following code, but it is not working. I am getting back an error “ERROR: Variable Profit is not on file WORK.YTD.”, Any idea, why this might be happening?

Code:

Data Profit;
Set YTD;
Profit=Sales*0.25;
Where Profit>3;
run;

Looking forward to your replies.

Thanks,


#2

Use IF in place of Where.


#3

Thanks Imran, It is working now. Please help to understand, why “Where statement” has not solved it?


#4

Steve,

“Where” and “if” are both used for sub-setting. Most of the times where and if can be used interchangeably in data step for sub-setting. But, when sub-setting is done on a newly created variable, only if statement can be used because IF performs sub-setting b/w PDV and Output data-set whereas Where b/w Input data-set and PDV.

Regards,
Imran