DATA Step, Macro, Functions and more

do until eof with an empty dataset

Accepted Solution Solved
Reply
Super Contributor
Posts: 354
Accepted Solution

do until eof with an empty dataset

Hello,

 

The following program :

 

data empty_class;
    set sashelp.class;
    stop;
run;

data _NULL_;
    put "1";

    eof=0;
    do until (eof);
        set sashelp.class end=eof;
        put name;
    end;

    put "2";

    eof=0;
    do until (eof);
        set empty_class end=eof;
        put name;
    end;

    put "3";
run;

gives the following output in the log :

1
Alfred
Alice
Barbara
Carol
Henry
James
Jane
Janet
Jeffrey
John
Joyce
Judy
Louise
Mary
Philip
Robert
Ronald
Thomas
William
2
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: There were 0 observations read from the data set WORK.EMPTY_CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

Why is "3" not displayed and how can it be fixed ?

 

Thanks !


Accepted Solutions
Solution
‎01-05-2018 09:18 AM
Super User
Posts: 10,530

Re: do until eof with an empty dataset

[ Edited ]

Trying to read from an empty dataset immediately throws you to the end of the data step, bypassing all remaining statements.

Compare this:

data _null_;
put 'before';
set empty_class;
put 'after';
run;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎01-05-2018 09:18 AM
Super User
Posts: 10,530

Re: do until eof with an empty dataset

[ Edited ]

Trying to read from an empty dataset immediately throws you to the end of the data step, bypassing all remaining statements.

Compare this:

data _null_;
put 'before';
set empty_class;
put 'after';
run;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 1,400

Re: do until eof with an empty dataset

Because the SET statement ends the DATA step because there are no observations to read in your second do until loop

Super Contributor
Posts: 354

Re: do until eof with an empty dataset

Thank you @KurtBremser and @draycut.

I thought the set on sashelp.class would avoid early termination.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 460 views
  • 0 likes
  • 3 in conversation