Date: Thu, 30 Jun 2011 04:03:20 -0400
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: macro: symbolic reference not resolved
Content-Type: text/plain; charset=ISO-8859-1
Franco,
I think that what happens is that the EXECUTE statement submits stuff to
the macro processor while the datastep containing the EXECUTE statement
is still running - thus the CALL SYMPUTX statements have not executed
yet when the matcher macro sends its second datastep to the macro
interpreter.
When the datasteps in the macro then execute, the macro variables finally
spring into existence, the macro processor resolves them, and everything
works fine. Until somebody defines a global variable nrowsA (or one of
the others), in which case the global value will be used instead of the
one from SYMPUTX.
I would recommend rearranging the execution a bit, by making the nrows
values parameters to the macro, and extract the values in the CALL EXECUTE
datastep (code not tested):
%macro matcher(vars,nrowsA,nrowsB,nrowsC,nrowsD);
*** macro second datastep here;
%mend;
data _NULL_;
array nrows (*) 8 nrows1-nrows4;
set mydataset;
do _N_=1 to 4;
dsid=open(catx('_',name,_N_));
nrows(_N_)=attrn(dsid,'NLOBS');
call close(dsid);
end;
call execute(cats('%matcher(',catx(',',name,of nrows(*)),')');
run;
I also used the NLOBS (No. of logical observations) instead of the
NOBS attribute - that way, the macro will also work if the tables
contain observations that were deleted with e.g. PROC SQL or FSEDIT.
Regards,
Søren
On Thu, 30 Jun 2011 01:56:01 -0400, Franco Grex <franco@GREX.ORG> wrote:
>Hi, this macro below gives the expected results but I keep getting the
>warnings:
>apparent symbolic reference to 'NROWSA' (and 'NROWSB' 'NROWSC'
>'NROWSD') not resolves?
>
>%macro matcher (vars);
> data _null_;
> if 0 then set &vars._1 nobs=nA;
> call symputx('nrowsA',nA);
> if 0 then set &vars._2 nobs=nB;
> call symputx('nrowsB',nB);
> if 0 then set &vars._3 nobs=nC;
> call symputx('nrowsC',nC);
> if 0 then set &vars._4 nobs=nD;
> call symputx('nrowsD',nD);
> stop;
> run;
> data &vars._Isquare (keep = pt1 retsas1-retsas6);
> array pt(1) $ 20;
> pt(1)= "&vars";
> array arrA(&nrowsA) $ 50 _temporary_;
> array arrB(&nrowsB) $ 50 _temporary_;
> array arrC(&nrowsC) $ 50 _temporary_;
> array arrD(&nrowsD) $ 50 _temporary_;
> do i=1 to &nrowsA;
> set &vars._1;
> arrA(i) = Location||Age||Sex||Income||N_1;
> end;
> NvarA=dim(arrA) * 50;
> do i=1 to &nrowsB;
> set &vars._2;
> arrB(i) = Location||Age||Sex||Income||N_2;
> end;
> NvarB=dim(arrB) * 50;
> do i=1 to &nrowsC;
> set &vars._3;
> arrC(i) = Location||Age||Sex||Income||N_3;
> end;
> NvarC=dim(arrC) * 50;
> do i=1 to &nrowsD;
> set &vars._4;
> arrD(i) = Location||Age||Sex||Income||N_4;
> end;
> NvarD=dim(arrD) * 50;
> array retsas(6);
> call module ("library, function", arrA(1), NvarA, arrB(1),
>NvarB, arrC(1), NvarC,
> arrD(1), NvarD, retsas(1));
> run;
> proc append base=Output_data data=&vars._Isquare force;
> run;
> proc datasets;
> delete &vars.A_1 &vars.B_2 &vars.C_3 &vars.D_4
> &vars._1 &vars._2 &vars._3 &vars._4 &vars._Isquare; run;
> %mend;
>
>*Execute the program;
>data _null_;
> set mydataset;
> call execute('%matcher('||name||')');
>run;
>
>Thanks
|