sas - Resolving macro variables in hash declaration? -
running bit unusual. feel silly error on part, life of me can't figure out be.
the following works fine:
declare hash hash&foo1.&foo2.&foo3.&foo4.(); ... the following not work:
declare hash hash%do bar = 1 %to &nvars.;&&foo&bar..%end;(); ... they both appear resolve
declare hash hash1111(); but latter throws syntax error. thoughts? specific error is:
line generated macro variable "foo1". 1 error 22-322: syntax error, expecting 1 of following: name, (, ;. ... declare hash hash1111(); note: line generated macro variable "foo4". hash1111
if want generate code fragments, before use fragment.
following code illustration:
%macro test; %global foobar; %let foobar = ; %let foo1 = 1; %let foo2 = 1; %let foo3 = 1; %let foo4 = 1; %let foobar = &foo1.; %do bar = 2 %to 4; %let foobar = %sysfunc(cats(&foobar., &&foo&bar..)); %put *&foobar.*; %end; %mend; %test; now kann use macrovariable foobar wherever like. e.g.
declare hash hash&foobar.(); aftersome research found solution in http://www2.sas.com/proceedings/sugi28/011-28.pdf
you need unquote macro loop. don't know why, following code working:
%macro test3(); %global foobar; %let foobar =; %let foo1 = 1; %let foo2 = 1; %let foo3 = 1; %let foo4 = 1; data test2; declare hash hash%unquote(%do bar = 1 %to 4;&&foo&bar..%end;)(); run; %mend; %test3; the following statement of sugi-paper lead solution: "in case, older documentation gave simple rule:
if mprint looks , sas compiler not understand it, try %unquote."
Comments
Post a Comment