BookmarkSubscribeRSS Feed
kkgogoi870
Calcite | Level 5

data test;
num = 5;
set sashelp.class point = num ;
output;
stop;
run;
proc print ; run;

 

Hi, could you please explain the code given above and elaborate why does it keep running on a loop without the "STOP" keyword.

 

Thank you

 

3 REPLIES 3
AMSAS
SAS Super FREQ

 @ kkgogoi870

 

The POINT option tells SAS to read a specific observation from a SAS dataset, and what your code is going to do (without the STOP), is read observation #5, write that to the output dataset, then go back to the top of the data step and read observation #5, write that to the output dataset, and continue to do that over and over.

 

Please refer to the POINT option documentation

CAUTION:
Continuous loops can occur when you use the POINT= option.
When you use the POINT= option, you must include a STOP statement to stop DATA step processing, or programming logic that checks for an invalid value of the POINT= variable, or both. Because POINT= reads only those observations that are specified in the DO statement, SAS cannot read an end-of-file indicator as it would if the file were being read sequentially. Because reading an end-of-file indicator ends a DATA step automatically, failure to substitute another means of ending the DATA step when you use POINT= can cause the DATA step to go into a continuous loop. If SAS reads an invalid value of the POINT= variable, it sets the automatic variable _ERROR_ to 1. Use this information to check for conditions that cause continuous DO-loop processing, or include a STOP statement at the end of the DATA step, or both.

 

 

Astounding
PROC Star

It helps to understand why this simple DATA step ends:

 

data new;

set old;

num=5;

run;

 

The SET statement will read the observations one at a time.  If there are 100 observations in OLD, they each get read in separately.  However, reading the 100th observation does not end the DATA step.  Instead, the SET statement continues and tries to read the 101st observation.  Since there is no 101st observation, that's when the DATA step ends.  The key step is trying to read another observation, and finding that there are no more observations to read.

 

Compare that to the DATA step that you posted.  Because of POINT= the SET statement always finds an observation.  The normal mechanism to end the DATA step (having the SET statement fail to find the observation it is looking for) never comes into play.  That's why you get an infinite loop without the STOP statement.

kiranv_
Rhodochrosite | Level 12

An excellent answer.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 807 views
  • 6 likes
  • 4 in conversation