LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 4 Nov 2005 18:38:04 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Re: Forcing SAS to print the resolved value of macro variables in
              the log
Comments: cc: Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU>

Scott,

The simple answer.

1 options mprint; 2 %let foo=bar; 3 options symbolgen ; SYMBOLGEN: Macro variable FOO resolves to bar 4 title "&foo"; SYMBOLGEN: Macro variable FOO resolves to bar 5 data &foo ; 6 &foo = "&foo" ; SYMBOLGEN: Macro variable FOO resolves to bar SYMBOLGEN: Macro variable FOO resolves to bar 7 run ; NOTE: The data set WORK.BAR has 1 observations and 1 variables.

The following is based on "Make Your Own Macro Processor" in NESUG 1999 hints at a more sophisticated solution. (Search words "whitlock" "processor" at <http://www.lexjansen.com/nesug/index.htm>)

filename code temp ; data _null_ ; array lkup (2) $ 32 _temporary_ ( "foo", "out" ) ; length line $ 256 ; infile cards truncover ; input line $char100. ; if index ( line , '&' ) then do ; do i = 1 to dim ( lkup ) ; line = tranwrd ( line , '&'||trim(lkup[i])||'.' , trim(symget(lkup[i])) ) ; end ; end ; file code ; put line $char50. ; cards4 ; options mprint; %let foo=bar; %let out = junk ;

title "&foo."; data &out. ; &foo. = "&out." ; run ;

/* more code */ ;;;;

%inc code / source2 ;

The PRX functions together with RESOLVE might speed up and allow more sophisticated processing, eg &&&var &&v&i etc. I think the paper has the code in a macro and the array of macro variable names is constructed automatically from the %LET statements. Note that in the above code the "." ender is essential, but with more testing it could be eliminated.

Ian Whitlock ================== Date: Sat, 5 Nov 2005 01:37:48 +1100 Reply-To: Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU> Sender: "SAS(r) Discussion" From: Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU> Subject: Re: Forcing SAS to print the resolved value of macro variables in the log Comments: To: sas-l Thanks Ron, that was a typo. That will teach me to try to improve the posted testcase without retesting. I've corrected the code below. "Scott Bass" <usenet739_yahoo_com_au> wrote in message news:436a97b1$0$1745$5a62ac22@per-qv1-newsreader-01.iinet.net.au... > Hi, > > Summary: > > Submit this code: > > 1 options mprint; > 2 %let foo=bar; > 3 title "&foo"; <<<<< > 4 %macro foo; > 5 title "&foo"; > 6 %mend; > 7 %foo; > MPRINT(FOO): title "bar"; <<<<< > > I wish there was some way I could force line 3 in the log to be the > resolved value of the macro variable, like line 7, rather than the macro > variable reference. > > Details/Rationale: > > We have an SDLC requirement to document the test cases within our > programs. The problem is, our test case documentation was always out of > sync with the test cases in the programs themselves. > > Therefore, I wrote a Perl script (thanks comp.lang.perl but, man, what a > TOUGH crowd on the newbies) plus a bit of SAS (thanks Richard) that parses > .sas or more often .log files for specially formatted comment blocks, and > generates the test case documentation. This is analogous to JavaDoc or > Perl POD, where the documentation for the program is embedded in the > program itself. > > I've encountered a problem, for which I need to come up with a > workaround/best practice. If the documentation block contains macro > variable references, outside of a macro, the SAS log will print the macro > variable reference, rather than the resolved value. Therefore, the > reference, rather than the value, ends up in the doc. > > My Perl script does handle/parse out the "MPRINT (FOO):" text, so the > immediate workaround is to force the end user to use a macro if the test > case block contains macro variables. However, this does add > complexity/additional code, just to get the log to read "properly". I was > hoping there was some magical, undocumented, whizbang SAS option that > would give me what I want. > > Or some brilliant idea/alternate approach/workaround from a fellow > SAS-L'er. > > Cheers, > Scott >


Back to: Top of message | Previous page | Main SAS-L page