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 09:34:28 -0400
Reply-To:     "Diskin, Dennis" <Dennis.Diskin@PHARMA.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Diskin, Dennis" <Dennis.Diskin@PHARMA.COM>
Subject:      Re: macro Q: avoiding temp file for generated statements
Comments: To: Michael Friendly <friendly@HOTSPUR.PSYCH.YORKU.CA>
Content-Type: text/plain; charset="iso-8859-1"

Two methods that come to mind are:

1. read the entire symbol file into indexed macro variables and use a macro to loop through them to produce the SYMNBOL statements. This amounts to using the macro space as your buffer.

2. Use a macro to produce the SYMBOL statements by reading the ds2symbol file via sysfunc calls to various IO functions. This is a more direct approach but, I wouldn't recommend it unless you have experience in programming I/O operations.

A quick prototype example of #1 (Untested)

/* Read symbol table into macro variables */ /* If you don't like SQL, this could also be done via a data step / Call symput */ proc sql noprint; select value,interpol, color, font, line, ci, co, height, width, repeat into :value1 thru :value999, :intr1 thru :intr999, :color1 thru :color999, :font1 thru :font999, :line1 thru :line999, ci1 thru :ci999, :co1 thru :co999, :high1 thru :high999, :wide1 thru :wide999, :rep1 thru :rep999 from test; %let nsymb = &sqlobs;

%macro symb; %local i; %do i = 1 to &nsymb; SYMBOL %if &&value ^=' ' %then %do; value= &&value&i %end;; %if &&intr&i ^=' ' %then %do; interpol= &&intr&i %end; ; %if &&color&i ^=' ' % then %do; color= &&color&i %end; %if &&font&i ^=' ' % then %do; font= &&font&i %end; %if &&ci&i ^=' ' %then %do; ci= &&ci&i %end; %if &&co&i ^=' ' %then %do; co=&&co&i %end; %if &&line&i ^=. %then %do; line= &&line&i %end; %if &&high&i ^=. %then %do; height= &&high&i %end; %if &&wide&i ^=. %then %do; width= &&wide&i %end; %if &&rep&i ^=. %then %do; repeat= &&rep&i %end; ; %mend;

/* then call the macro where you want the SYMBOL statements to appear */

hth, Denis Diskin

> ----Original Message----- > From: Michael Friendly [SMTP:friendly@HOTSPUR.PSYCH.YORKU.CA] > Sent: Friday, July 20, 2001 12:08 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: macro Q: avoiding temp file for generated statements > > 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. > > 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: friendly@yorku.ca (NeXTmail OK) > 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