[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: Questionable macro resolution behavior
From:       Scott <usenet739_yahoo_com_au () CRONKITE ! CC ! UGA ! EDU>
Date:       2004-12-31 1:12:38
[Download RAW message or body]

Thanks Jack, both of these are improvements over my original post, and are
tips I'm sure I will use in the future!

"Jack Hamilton" <JackHamilton@FIRSTHEALTH.COM> wrote in message
news:s1d3d609.078@SLCM02.firsthealth.com...
> The %sysfunc macro funcation accepts a second argument which is the name
> of a format to be applied to the result.  I think that's a cleaner
> solution than running the output through a second %sysfunc.
>
>   %let theyear = %sysfunc(today(), year4.);
>
> Also, the documentation mentions that, if you use SEPARATED with INTO,
> leading and trailin blanks will be trimmed.  So you could use
>
>   select count(distinct x) into :count separated by '' from one;
>
>   select format into :varformat separated by '' from
> dictionary.columns
>      where libname="WORK" and memname="ONE" and
> upcase(name)="%upcase(x)";
>
> and skip the post processing.
>
>
>
>
> --
> JackHamilton@FirstHealth.com
> Manager, Technical Development
> Metrics Department, First Health
> West Sacramento, California USA
>
> Coelum, non animum mutant, qui trans mare currunt.
>
>
>>>> "Scott" <usenet739_yahoo_com_au@CRONKITE.CC.UGA.EDU> 12/29/2004
> 8:56 PM >>>
> 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
>
>
> "MMS <firsthealth.com>" made the following annotations.
> ------------------------------------------------------------------------------
> This message, including any attachments, is intended solely for the use
> of the named recipient(s) and may contain confidential and/or
> privileged information.  Any unauthorized review, use, disclosure or
> distribution of this communication(s) is expressly prohibited.
> If you are not the intended recipient, please contact the sender by
> reply e-mail and destroy any and all copies of the original message.
> Thank you.
> ==============================================================================

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic