Where statement is not working in SAS

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?


Data Profit;
Set YTD;
Where Profit>3;

Looking forward to your replies.


Use IF in place of Where.

1 Like

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


“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.


1 Like
© Copyright 2013-2019 Analytics Vidhya