Date: Sun, 15 Jul 2007 10:04:30 -0700
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott Barry <sbarry@SBBWORKS.COM>
Subject: Re: Writting Values in Macro
Content-Type: text/plain; charset="us-ascii"
On Jul 15, 11:00 am, schmi...@UWM.EDU ("Thomas A. Schmitt") wrote:
> Hello Group:
> I am trying to write values to a data set in a macro loop. At this point each
> value overwrites the previous value. What I would like is for each value to be
> written to the subsequent row in each loop. Any suggestions are appreciated!
> The program is below.
> Best regards,
> %LET nreps = 2;
> %MACRO reps;
> %DO k = 1 %TO &nreps;
> %put "Starting loop &k";
> DATA HGLM_estimate (KEEP = r_00m_e);
> INFILE "C:\HGLM_&k..txt";
> INPUT text $char200.;
> IF INDEXW(text,'INTRCPT1/INTRCPT2, U00') THEN DO r_00m_e = SCAN(text,3,' ');
> DATA r_00m_estimate;
> SET HGLM_estimate;
> IF r_00m_e ^= . ;
> PROC PRINT DATA=r_00m_estimate;
> %PUT "Ending loop &k";
> OPTIONS NOXWAIT;
One approach is to have your %DO / %END loop to work within a single
DATA step, so that only one output file is generated, while processing
each input file. You can use the INFILE parameter
END=eof&k._condition_variable to set a DATA step variable and have a
DATA step DO UNTIL eof&k._condition_variable / END loop to process
each input file, again within your %DO / %END loop process. You will
also want include an explicit OUTPUT statement within your DATA step
DO / END loop iterations, since you would will only be running through
the entire DATA step once.
Lastly, my preference is to code a STOP; statement at the end of the
DATA step, after your repeating DO/END loop executions.
A useful diagnostic technique here would be to maximize the SASLOG
output by setting options SOURCE SOURCE2 MACROGEN SYMBOLGEN MLOGIC
NOMPRINT (another personal preference).