|
the macro variables you created in macro dcnt is local inside the macro
definition. after finishing the execution of that macro call, the macro
variables will be automatically deleted. any outside reference will not be
resolved. you may define them as global varibles without changing your
original design.
HTH
Yu
On 1/3/07, Nirmal <lazybone2k@gmail.com> wrote:
>
> SAS-l users,
>
> A quick question.
> I wrote the following code to find out the number of levels of the
> variables in a dataset.
>
> I got the variables names in a macro array using call symput and here in
> the following code I am trying to find out the number of levels in the
> variable by using the first.variable function.
>
> &&n&i - variables in a macro array
> &dimobs - number of variables in the macro array.
> &dimcnt&i - levels of the variable in the same order as the variable
> array.
>
> The sample data set is as follows.
> Market Buyer Product
> A1 B1 C1
> A1 B1 C2
> A1 B2 C3
> A1 B2 C4
>
>
> %Macro dcnt;
> %do i = 1 %to &dimobs.;
> proc sort data = tdata(keep = &&n&i) out = tdata1;
> by &&n&i;
> run;
> data _null_ ;
> set tdata1;
> By &&n&i ;
> if first.&&n&i then do;
> CNT+1 ;
> end;
> Call symput('dimcnt'||left(&i),left(trim(cnt)));
> Run ;
> %put &&dimcnt&i;
> %end;
> %mend dcnt;
> run;
>
> %dcnt;
> run;
>
> %macro test;
> %do a= 1 %to &dimobs.;
> %put &&dimcnt&a;
> %end;
> %mend test;
> run;
>
> %test;
>
> Whenever i execute this code, i get the following error - the &&dimcnt&i
> is
> not resolving.
> MLOGIC(TEST): Beginning execution.
> SYMBOLGEN: Macro variable DIMOBS resolves to 3
> MLOGIC(TEST): %DO loop beginning; index variable A; start value is 1;
> stop
> value is 3; by value is 1.
> MLOGIC(TEST): %PUT &&dimcnt&a
> SYMBOLGEN: && resolves to &.
> SYMBOLGEN: Macro variable A resolves to 1
> WARNING: Apparent symbolic reference DIMCNT1 not resolved.
>
> Any suggestion or tips would be really appreciated. Thanks.
>
> Regards,
> Nirmalkumar Sugumar
> lazybone2k@gmail.com
>
|