Hi,
in the Certification book (Base) i found this question:
There is no end-of-file condition when you use direct access to read data, so how can
your program prevent a continuous loop?
a. Do not use a POINT= variable.
b. Check for an invalid value of the POINT= variable.
c. Do not use an END= variable.
d. Include an OUTPUT statement.
with this answer
Correct answer: b
To avoid a continuous loop when using direct access, either include a STOP
statement or use programming logic that executes a STOP statement when the data
step encounters an invalid value of the POINT= variable. If SAS reads an invalid
value of the POINT= variable, it sets the automatic variable _ERROR_ to 1. You can
use this information to check for conditions that cause continuous looping.
I understand the use of STOP statement but i can't realy figure out what the "invalid value" can be used. Can someone explain better or with other words what does this answer mean ? And maybe post some example code ?
thanks,
Arjuna
Looks like a really poor question.
If you are using a loop of some sort with POINT= option on SET to do access you could also use NOBS= option so you know how many observations there are.
data want;
do p=1 to nobs;
set have point=p nobs=nobs;
output;
end;
stop;
run;
If you are reading a list of observation numbers from another dataset then you could also use NOBS to check before even trying to use POINT=. No need for a STOP statement in this case as the step will stop when it reads past the end of the dataset RECORD_LIST.
data want ;
set record_list;
if 1 <= recno <= nobs then set have point=recno nobs=nobs;
else put 'Hey there is no observation number ' recno ;
run;
Of like they said you could just check the _ERROR_ variable and assume that means you tried to read something that wasn't there and stop.
data want ;
set sashelp.class point=_n_ ;
if _error_ then do;
put 'Somthing happened.' _n_=;
stop;
end;
else output;
run;
Looks like a really poor question.
If you are using a loop of some sort with POINT= option on SET to do access you could also use NOBS= option so you know how many observations there are.
data want;
do p=1 to nobs;
set have point=p nobs=nobs;
output;
end;
stop;
run;
If you are reading a list of observation numbers from another dataset then you could also use NOBS to check before even trying to use POINT=. No need for a STOP statement in this case as the step will stop when it reads past the end of the dataset RECORD_LIST.
data want ;
set record_list;
if 1 <= recno <= nobs then set have point=recno nobs=nobs;
else put 'Hey there is no observation number ' recno ;
run;
Of like they said you could just check the _ERROR_ variable and assume that means you tried to read something that wasn't there and stop.
data want ;
set sashelp.class point=_n_ ;
if _error_ then do;
put 'Somthing happened.' _n_=;
stop;
end;
else output;
run;
Is this the Advanced Guide? The Base certification doesn't cover EOF/POINTER access the last time I checked...though I could easily be mistaken.
@arjunascagnetto wrote:
Hi,
in the Certification book (Base) i found this question:
There is no end-of-file condition when you use direct access to read data, so how can
your program prevent a continuous loop?
a. Do not use a POINT= variable.
b. Check for an invalid value of the POINT= variable.
c. Do not use an END= variable.
d. Include an OUTPUT statement.
with this answer
Correct answer: b
To avoid a continuous loop when using direct access, either include a STOP
statement or use programming logic that executes a STOP statement when the data
step encounters an invalid value of the POINT= variable. If SAS reads an invalid
value of the POINT= variable, it sets the automatic variable _ERROR_ to 1. You can
use this information to check for conditions that cause continuous looping.
I understand the use of STOP statement but i can't realy figure out what the "invalid value" can be used. Can someone explain better or with other words what does this answer mean ? And maybe post some example code ?
thanks,
Arjuna
Any negative value or value of point greater than the number of records in the data set would be invalid. So if your program sets the point variable to a value outside the range of records in the data set you get into problems.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.