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 (July 2001, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 23 Jul 2001 15:57:18 -0500
Reply-To:     Paul Thompson <paul@WUBIOS.WUSTL.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Thompson <paul@WUBIOS.WUSTL.EDU>
Organization: Washington University in St. Louis
Subject:      Re: macro Q: avoiding temp file for generated statements
Content-Type: text/plain; charset=us-ascii

Paul Thompson wrote:

> Michael Friendly wrote: > > > I have a macro, ds2symb, designed to generate SYMBOL statements > > from a data set. As you'll see below, I use a data _null_ step > > to write those statements to a temporary file, then %include > > them. > > > > YUCK!!! Why not use CALL EXECUTE to do this? > > CALL EXECUTE is one of the great new (?) approaches in SAS. You set up > statements TO BE EXECUTED at the next data step boundary. > > In your case, you will do something like: > > data _null_; > set &data end=eof; > length symbline $200; > NO FILE SYMBOL STATEMENT > symbline=compress('symbol'||put(_n_,3.)); > if &value ^=' ' then symbline=trim(symbline)||" value=&value"; > if &interpol ^=' ' then symbline=trim(symbline)||" > interpol=&interpol"; >

FORGOT TO TRIM my line. That TRIM() is really important.

> > etc.etc. > etc > call execute(symbline); > if eof then do; > file log; > put 'NOTE:' _n_ ' SYMBOL statements have been generated'; > end; > > run; > > > > > For several reasons (e.g., file names are not portable) I'd like > > to avoid using a temporary file, but can't quite remember how > > to do this. > > > > Who can help? > > > > ---- ds2symb.sas ---- > > /* > > Generate SYMBOL statements from a data set, to allow setting > > combinations of symbols, colors, line styles, etc. programatically. > > */ > > %macro ds2symb( > > data=_last_, > > value=value, /* name of the VALUE= variable */ > > interpol=interpol, /* name of the INTERPOL= variable */ > > color=color, /* name of the COLOR= variable */ > > font=font, /* name of the FONT= variable */ > > line=line, /* name of the LINE= variable */ > > ci=ci, /* name of the CI= variable */ > > co=co, /* name of the CO= variable */ > > height=height, /* name of the HEIGHT= variable */ > > width=width, /* name of the WIDTH= variable */ > > repeat=repeat /* name of the REPEAT= variable */ > > ); > > > > %*tempfile(symbol); > > filename symbol '/tmp/symbol.out'; > > > > data _null_; > > set &data end=eof; > > file symbol; > > put 'symbol' +0 _n_ @; > > if &value ^=' ' then put 'value=' +0 &value @; > > if &interpol ^=' ' then put 'interpol=' +0 &interpol @; > > if &color ^=' ' then put 'color=' +0 &color @; > > if &font ^=' ' then put 'font=' +0 &font @; > > if &ci ^=' ' then put 'ci=' +0 &ci @; > > if &co ^=' ' then put 'co=' +0 &co @; > > > > if &line ^=. then put 'line=' +0 &line @; > > if &height ^=. then put 'height=' +0 &height @; > > if &width ^=. then put 'width=' +0 &width @; > > if &repeat ^=. then put 'repeat=' +0 &repeat @; > > put ';'; > > > > if eof then do; > > file log; > > put 'NOTE:' _n_ ' SYMBOL statements have been generated'; > > end; > > > > run; > > > > %include symbol; > > > > %* clear the fileref and delete the temp file; > > %*tempdel(symbol); > > %mend; > > > > data testit; > > height=1; > > interpol='none'; > > line=1; > > do color='red ', 'blue'; > > do value='plus ', 'dot', 'square'; > > output; > > end; > > end; > > run; > > > > options mprint; > > %ds2symb(data=testit); > > > > -- > > Michael Friendly Email: > > Psychology Dept > > York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 > > 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html > > Toronto, ONT M3J 1P3 CANADA


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