BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
animesh123
Obsidian | Level 7

Table a

x=10

y=25

 

Data b;

set a;

z=x+y

wherez>30 then output;run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

SAS Where statement in a data step requires reference to values in data sets on the SET statement. So "where z" is not valid. Also WHERE does not use "then" in any form. The purpose of where is selection of records so specifically a "then output" would be redundant.

You could use to select records such that x+y is > 30 if you really want to use where.

Data b;
  set a;
  where (x+y)>30;
run;

If you need the variable z you would have to create it.

Or use an IF. This is a "sub-setting if"

data b2;
  set a;
  z= x+y;
  if z>30;
run;

The only observations processed after the IF will be those where the If is true. So the implied output at the end of the data step makes this equivalent to

data b2;
  set a;
  z= x+y;
  if z>30 then output;
run;

Hint:

Provide your example data in the from of a working data step such as:

data a;
   input x y;
   datalines;
10 25
;

multiple lines of x y values in the datalines would allow testing more values.

 


@animesh123 wrote:

Table a

x=10

y=25

 

Data b;

set a;

z=x+y

wherez>30 then output;run;

 


 

View solution in original post

1 REPLY 1
ballardw
Super User

SAS Where statement in a data step requires reference to values in data sets on the SET statement. So "where z" is not valid. Also WHERE does not use "then" in any form. The purpose of where is selection of records so specifically a "then output" would be redundant.

You could use to select records such that x+y is > 30 if you really want to use where.

Data b;
  set a;
  where (x+y)>30;
run;

If you need the variable z you would have to create it.

Or use an IF. This is a "sub-setting if"

data b2;
  set a;
  z= x+y;
  if z>30;
run;

The only observations processed after the IF will be those where the If is true. So the implied output at the end of the data step makes this equivalent to

data b2;
  set a;
  z= x+y;
  if z>30 then output;
run;

Hint:

Provide your example data in the from of a working data step such as:

data a;
   input x y;
   datalines;
10 25
;

multiple lines of x y values in the datalines would allow testing more values.

 


@animesh123 wrote:

Table a

x=10

y=25

 

Data b;

set a;

z=x+y

wherez>30 then output;run;

 


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 1 reply
  • 685 views
  • 0 likes
  • 2 in conversation