DATA Step, Macro, Functions and more

Varname - argument 1 missing or out of range

Reply
New Contributor
Posts: 4

Varname - argument 1 missing or out of range

Hi there

I'm struggling with the following macro. I'm quite new to the macro language and picking it up as I go along, so it may well be something pretty fundamental that I've misunderstood.

%let ref = %sysfunc(open(libname.filename));

%macro name;

%do i = 5 %to &errstop;

     %let variname = %sysfunc(varname(&ref,&i));

...some more code...

%end;

%mend;

The log tells me that &errstop resolves to 25 and that &ref resolves to 1, but I then get the following error:

WARNING: Argument 1 to function VARNAME refrenced by the %SYSFUNC or %QSYSFUNC macro function is missing or out of range.

Can anyone help me to understand what that means, please?

Thanks

Katy


PROC Star
Posts: 7,471

Re: Varname - argument 1 missing or out of range

What is &errstop.?  When I ran your code, as shown below, and ran perfectly:

%let ref = %sysfunc(open(sashelp.class));

%macro name;

%do i = 1 %to 5;

     %let variname = %sysfunc(varname(&ref,&i));

     %put &variname.;

%end;

%mend;

%name

New Contributor
Posts: 4

Re: Varname - argument 1 missing or out of range

Interesting. It's a macro variable defined earlier on in the code but it hadn't occured to me from the error message that that's where the problem might be. I'll look at that bit more closey - thanks for your help.

New Contributor
Posts: 4

Re: Varname - argument 1 missing or out of range

Nope, I'm still getting the same error even if I replace the start and stop values for the do loop as you have done. The only other difference is the actual file I'm using - could there be something wrong with that?

New Contributor
Posts: 4

Re: Varname - argument 1 missing or out of range

OK, somewhat embarrassingly, I've found the error in some of the code I didn't reproduce. I'd accidentally got a close statement between the open statement and the macro, and now I've moved that it works fine. Thanks very much for your help, though - you got me looking wider to find the problem!

Ask a Question
Discussion stats
  • 4 replies
  • 439 views
  • 3 likes
  • 2 in conversation