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
On 1/3/07, Nirmal <email@example.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
> 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;
> data _null_ ;
> set tdata1;
> By &&n&i ;
> if first.&&n&i then do;
> CNT+1 ;
> Call symput('dimcnt'||left(&i),left(trim(cnt)));
> Run ;
> %put &&dimcnt&i;
> %mend dcnt;
> %macro test;
> %do a= 1 %to &dimobs.;
> %put &&dimcnt&a;
> %mend test;
> Whenever i execute this code, i get the following error - the &&dimcnt&i
> 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;
> 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.
> Nirmalkumar Sugumar