BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
George_S
Fluorite | Level 6

The two mathods get same result but what is their difference?

Thanks!

data class2;

set sashelp.class;

if age=12;

run;

data class3;

set sashelp.class;

where age=12;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Hima
Obsidian | Level 7

There is no difference at this instance but there is a difference at other instances. One example would be

data exam;
input name $ class $ score ;
if name = 'Tim' or name = 'Sally';
cards;
Tim math 9
Tim history 8
Tim science 7
Sally math 10
Sally science 7
Sally history 10
John math 8
John history 8
John science 9
;
run;

proc print; run;

Output:

                                Obs    name     class      score

                                 1     Tim      math          9
                                 2     Tim      history       8
                                 3     Tim      science       7
                                 4     Sally    math         10
                                 5     Sally    science       7
                                 6     Sally    history      10

data exam;
input name $ class $ score ;
where name = 'Tim' or name = 'Sally';
cards;
Tim math 9
Tim history 8
Tim science 7
Sally math 10
Sally science 7
Sally history 10
John math 8
John history 8
John science 9
;
run;

proc print; run;

Log:

736  data exam;

737  input name $ class $ score ;

738  where name = 'Tim' or name = 'Sally';

ERROR: No input data sets available for WHERE statement.

739  cards;


View solution in original post

5 REPLIES 5
Hima
Obsidian | Level 7

There is no difference at this instance but there is a difference at other instances. One example would be

data exam;
input name $ class $ score ;
if name = 'Tim' or name = 'Sally';
cards;
Tim math 9
Tim history 8
Tim science 7
Sally math 10
Sally science 7
Sally history 10
John math 8
John history 8
John science 9
;
run;

proc print; run;

Output:

                                Obs    name     class      score

                                 1     Tim      math          9
                                 2     Tim      history       8
                                 3     Tim      science       7
                                 4     Sally    math         10
                                 5     Sally    science       7
                                 6     Sally    history      10

data exam;
input name $ class $ score ;
where name = 'Tim' or name = 'Sally';
cards;
Tim math 9
Tim history 8
Tim science 7
Sally math 10
Sally science 7
Sally history 10
John math 8
John history 8
John science 9
;
run;

proc print; run;

Log:

736  data exam;

737  input name $ class $ score ;

738  where name = 'Tim' or name = 'Sally';

ERROR: No input data sets available for WHERE statement.

739  cards;


George_S
Fluorite | Level 6

Thanks!

Linlin
Lapis Lazuli | Level 10

some other differences:

data class3;

set sashelp.class(where=(age=12));/*you can't replace where with if */

run;

/***********************************/

data class4;

  set sashelp.class;

  newage=age+2;

  if newage>15;/*you can't replace if with where */

run;

/*********************************/

proc print data=sashelp.class;

  where age>14;

run;/*you can't replace where with if */

/*************************************/

data class5;

   set sashelp.class;

   where age between 12 and 14;

run;/*you can't replace where with if */

Linlin

Haikuo
Onyx | Level 15

Please correct me if I am wrong, my not-so-accurate memory tell me that the major difference between where and if lies on the where they function.

'if' acts in between pdv and output, also in a sequential way; while 'where' plays before pdv in a random access way, that is also why 'where' can work with index.

Haikuo

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2272 views
  • 7 likes
  • 5 in conversation