Help using Base SAS procedures

what is the difference?

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

what is the difference?

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;


Accepted Solutions
Solution
‎04-11-2012 04:17 PM
Regular Contributor
Posts: 233

Re: what is the difference?

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


All Replies
Solution
‎04-11-2012 04:17 PM
Regular Contributor
Posts: 233

Re: what is the difference?

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;


Contributor
Posts: 35

Re: what is the difference?

Thanks!

PROC Star
Posts: 7,467

Re: what is the difference?

Super Contributor
Posts: 1,636

Re: what is the difference?

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

Respected Advisor
Posts: 3,156

Re: what is the difference?

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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