02-20-2015 02:36 AM
Hi, Can anybody explain why the below code does not need a STOP statement and how it manages to detect the end of file?
set sashelp.class(rename=(name=name1 age=age1 sex=gender height=ht1 weight=wt1));
do i=1 to nobs by 3;
set a point=i nobs= nobs;
The code works fine, but i am not understanding how does it do without a STOP statement..The SAS documentation says STOP is a must when we use point= option though. Also, why is my index variable I not written to the output dataset w? I never explicitly dropped it with drop= or drop statement?
02-20-2015 02:44 AM
This data step executes the do loop completely for every observation in sashelp.class and ends when EOF of sashelp.class is reached.
02-20-2015 05:51 AM
If you have added STOP, you would have got 7 observations. Since there is no STOP it goes on 19 times --- the number of observations in SASHELP.CLASS -- and after finding the EOF in that dataset, Data Step default action stop the iteration. So your output data sets gets 19 times 7 observations (133 observations).
The variable I need no drop because, any variable used to point to POINTER =, will not go to the Program Data Vector and hence does not appear in the output data set.
02-20-2015 06:46 AM
The data step stops when it reads past the end of SASHELP.CLASS in the second statement.
Variables defined by POINT= and NOBS= (and other similar options) are NOT written to the output dataset.
02-20-2015 02:22 PM
To understand the answer, you have to understand how this DATA step stops:
You might see more information that would help if you added some diagnostic messages:
put "Before: " _all_;
put "After: " _all_;
Look at how many messages there are, and how many observations were read in. Once you understand that, we can switch back to your original question.