Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive reference to macro variable

Status
Not open for further replies.

Asender

Programmer
Jun 4, 2003
31
GB
Hi all.

Can anyone help me with this problem.

I am attempting to create a macro variable that is constructed from the variables names in a target dataset.

The code I am using is pulled from the following document.

'Comparing 2 SAS Data Sets: An alternative to Using PROC COMPARE'

The methodology used is also confirmed in the online SAS doc under the entry for VARNAME.

However, when I run the code I get the following.


%macro comp_obs(dsn1,dsn2);

%let dsid=%sysfunc(open(&dsn1,i));
%let nvar1=%sysfunc(attrn(&dsid,nvars));

%do i=1 %to &nvar1;
%let name1=%sysfunc(varname(&dsid,&i));
%let list1=%str( &list1 &name1 );
%end;

%mend comp_obs;

%comp_obs(as.mm92_now,as.mm92_then);
WARNING: Apparent symbolic reference LIST1 not resolved.
ERROR: The text expression  &LIST1 CHANNEL_ID  contains a recursive reference to the macro variable LIST1. The macro
variable will be assigned the null value.

Anyone got any ideas what I'm doing wrong, coz I'm stumped.

Thanks for reading,


Asender...
 
Yes you can't use the %str() when referencing the very macro var that you want to reset.
This statement is not correct.
Code:
 %let list1=%str( &list1 &name1 );

Take the %str() off.
Code:
 %let list1 = &list1 &name1 ;
I noticed that you do not have a close() in any sysfunc() macro functions. You are leaving the dataset opened and locked. You should have a %sysfunc(close(&dsid)) statement too.
By the way if all you are doing is getting a list of variable names into a macro string there is a nice way using proc SQL.

Code:
proc sql;
  select name into : List1
  separated by ' '
  from sashelp.vcolumn
  where trim(upcase(libname)) eq 'yourlibname' and
        trim(upcase(memname)) eq 'yourdatasetname';
quit;

You can test the results by using the %PUT statement.
Code:
%put List1 = &List1;

Hope this has helped you.
Klaz
 
Hi Klaz.

Thanks very much for the reply.

Yip, remove the %str and Bobs your uncle.

I had to initialise the macro variable list1 with a
Code:
 %let list1=

in order to get rid of the last error.

Believe it or not, I did come up with the proc sql solution myself (I must be getting better at this if I'm starting to think like you ;-) ).

But I hate to leave a problem unsolved hence the post. Do you know the reason why using the %str function causes this error?

Thanks again Klaz.

Regards,


Asender.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top