BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arjunascagnetto
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;

 

Reeza
Super User

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
Fluorite | Level 6
Guide for base programmer certification.
ballardw
Super User

@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.

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
  • 4 replies
  • 1849 views
  • 1 like
  • 4 in conversation