Help using Base SAS procedures

out of range error

Reply
Regular Contributor
Posts: 161

out of range error

Hi,
I am getting this error, can any one help me.
thank you

GETVARN referenced by the %SYSFUNC or %QSYSFUNC macro function
is out of range.

my code:
%MACRO SaveItemOrder;
%let ordervar=3;
DATA _NULL_;
/* Datasets to draw values from*/
%LET dataQmatrix=%SYSFUNC(OPEN(work.Qmatrix,i));
%DO i=1 %TO 7;
/* Assign new macro variables as global*/
%GLOBAL itemorder&i;
/* Gets entire row of data*/
%LET row=%SYSFUNC(FETCHOBS(&dataQmatrix,&i));
/* Grabs specific value for threshold from that row*/
%LET item&i.=%SYSFUNC(GETVARN(&dataQmatrix.,
%SYSFUNC(VARNUM(&dataQmatrix.,&ordervar.))));
/* Transferring value to global macro, and checking via log;*/
%LET itemorder&i. = &&item&i.;
%PUT itemorder&i. &&itemorder&i.;
%END;
/* Close dataset used in program;*/
%LET dataQmatrix=%SYSFUNC(CLOSE(&dataQmatrix.));
RUN;
%MEND;
%SaveItemOrder;
Occasional Contributor
Posts: 7

Re: out of range error

Hi R.A.G.

the problem is in second parametr of the GETVARN function. It should be the number of the variable in the Data Set.
from now you have 2 options:
1 . %LET item&i.=%SYSFUNC(GETVARN(&dataQmatrix.,&ordervar.));

2. if you want use VARNUM function you need change second paramets. Instead of &ordervar use var name.

Irena
Regular Contributor
Posts: 161

Re: out of range error

Hi Irena ,

Thanks that helped. I have another question. when using this function:
%LET item&i.=%SYSFUNC(GETVARN(&dataQmatrix.,&ordervar.));

Are we telling SAS to look at each row of the data or each column of the data?

Thanks again
R.G.
SAS Super FREQ
Posts: 8,743

Re: out of range error

Hi:
GETVARN returns the value of a numeric VARIABLE:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148384.htm

However, you cannot debug GETVARN separate from the OPEN, FETCHOBS VARNUM and CLOSE functions. They are all documented in the Function and Call Routine doc:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245852.htm

cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 323 views
  • 0 likes
  • 3 in conversation