BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

Hello,

How does this program execute?


data test;
	set sashelp.class;

	do until(eof);
		set sashelp.class end=eof;
	 output;
	end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Look at the log after running this and see if you get any enlightenment:

data test;
	set sashelp.class;
   put 'Before loop';
	do until(eof);
      put 'At begin of loop' +1 name=;
		set sashelp.class end=eof;
      put 'In loop after set' +1 name=;
	 output;
      put;
	end;
run;

View solution in original post

11 REPLIES 11
mkeintz
PROC Star

Form a hypothesis test it, report the results, and why you think those results occurred.  Then you'll get plenty of responses.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SAS_inquisitive
Lapis Lazuli | Level 10
@KurtBremser and @mkeintz I was wondering why two records are reading from first set statement?
mkeintz
PROC Star
  1. How many times do you think the complete loop    "do until (eof); ....... " is successfully run?

  2. What happens when a SET statement attempts to read beyond end of data?
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SAS_inquisitive
Lapis Lazuli | Level 10

@mkeintz  1.  "do until (eof); ....... "  runs just in one loop as it is DOW-LOOP setting.

                   2.  _n_ increments by 1 and implicit loop terminates.


data test;
    put _all_;
	set sashelp.class;
	put _all_;
run;

data test;
	
	put _all_;
	do until(eof);
      
		set sashelp.class end=eof;
		output;
    put _all_;
	end;
	
run;

  

ballardw
Super User

Look at the log after running this and see if you get any enlightenment:

data test;
	set sashelp.class;
   put 'Before loop';
	do until(eof);
      put 'At begin of loop' +1 name=;
		set sashelp.class end=eof;
      put 'In loop after set' +1 name=;
	 output;
      put;
	end;
run;
Rick_SAS
SAS Super FREQ

Building on ballardw's advice, try

data test;
	set sashelp.class(rename=(Name=FirstName));
   put 'Before loop';
	do until(eof);
      put 'At begin of loop' +1 FirstName=;
		set sashelp.class end=eof;
      put 'In loop after set' +1 FirstName= +1 name=;
	 output;
      put;
	end;
run;
SAS_inquisitive
Lapis Lazuli | Level 10
@Rick_SAS, renaming helped understand since the original solution was given by @Ballard, I accepted his solution. Thanks .
Kurt_Bremser
Super User

A nice variation to further illustrate the behaviour of set statements and loops:

data test;
  set sashelp.class;
  do while (not eof);
    set sashelp.class end=eof;
    output;
  end;
run;
PGStats
Opal | Level 21

The question you may want to ask instead is When does this program stop?

PG
SAS_inquisitive
Lapis Lazuli | Level 10
@PGStats, you are absolutely right.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1505 views
  • 8 likes
  • 6 in conversation