Date: Sun, 15 Jul 2007 10:04:30 -0700
Reply-To: sbarry@SBBWORKS.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott Barry <sbarry@SBBWORKS.COM>
Organization: http://groups.google.com
Subject: Re: Writting Values in Macro
In-Reply-To: <1184511657.469a36a943e6a@panthermail.uwm.edu>
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,
>
> Tom
>
> %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,' ');
> END;
> RUN;
>
> DATA r_00m_estimate;
> SET HGLM_estimate;
> IF r_00m_e ^= . ;
> PROC PRINT DATA=r_00m_estimate;
> RUN;
>
> %PUT "Ending loop &k";
> %END;
> %MEND;
> OPTIONS NOXWAIT;
> %reps
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).
Scott Barry
SBBWorks, Inc.
|