Date: Thu, 30 Dec 2004 15:56:57 +1100
Reply-To: Scott <usenet739_yahoo_com_au@CRONKITE.CC.UGA.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott <usenet739_yahoo_com_au@CRONKITE.CC.UGA.EDU>
Subject: Re: Questionable macro resolution behavior
Rather than use PROC SQL, esp. with the data x kludge, in your scenario,
would this meet your needs?
%let theyear = %sysfunc(year(%sysfunc(today())));
%put ***&theyear***;
Also, you can just re-assign a macro variable to itself to remove leading
and trailing spaces:
* testing... ;
data one;do x=1 to 10;output;end;format x 15.;run;
proc sql noprint;
select count(distinct x) into :count from one;
select format into :varformat from dictionary.columns
where libname="WORK" and memname="ONE" and upcase(name)="%upcase(x)";
quit;
%put ***&count***;
%put ***&varformat***;
%let count = &count; /* remove leading and trailing spaces */
%let varformat = &varformat;
%put ***&count***;
%put ***&varformat***;
HTH,
Scott
"Doug Rohde" <douglas.rohde@PRUDENTIAL.COM> wrote in message
news:200412291956.iBTJuNMm017680@listserv.cc.uga.edu...
> Has anybody else seen the following behavior when trying to get macro
> variables to resolve in the middle of a string? If I try to assign the
> macro variable THEYEAR programatically, it resolves with leading spaces,
> BUT ONLY if it's part of a larger string. But if I explicitly give
> THEYEAR
> value, it resolves correctly without the leading spaces. My sample code
> is
> below:
>
>
> /*BEGIN SAMPLE CODE*/
> data x; /*Proc SQL below requires a data set to select from*/
> foo=1;
> run;
>
> proc sql;
> select year(%sysfunc(date()))
> into:theyear
> from x;
> quit;
>
>
> %put &theyear;
>
> /*************** Log output:
> 81 %put &theyear;
> 2004
> ***************/
>
> %put bar_&theyear._baz;
>
> /************** Log output:
> 83 %put bar_&theyear._baz;
> bar_ 2004_baz
> **************/
>
> %let theyear=2004;
> %put bar_&theyear._baz;
>
> /************* Log output:
> 85 %let theyear=2004;
> 86 %put bar_&theyear._baz;
> bar_2004_baz
> **************/
>
> /*END SAMPLE CODE*/
>
>
> Does anybody know why this is happening? Is this a bug, or a "feature"?
>
> Doug R
|