| Date: | Thu, 6 Sep 2007 08:41:50 -0400 |
| Reply-To: | Paul St Louis <pstloui@DOT.STATE.TX.US> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Paul St Louis <pstloui@DOT.STATE.TX.US> |
| Subject: | Re: Double do loop inside macro |
|---|
Should you wish to pursue Toby's advice, here is some code previously
provided by Toby (and others)which reads in monthly pay files on WIN XP
system. With a little adaptation, it may suit your needs:
/* SET UP PAY FILES */
DATA CTSPAY;
LENGTH FILES2READ $ 50 ;
STOP = INTCK( 'MONTH' , '01DEC1997'D , '01MAR2007'D ) ;
DO INCREASEDATEBY = 1 TO STOP ;
DATE = INTNX( 'MONTH' , '01DEC1997'D , INCREASEDATEBY ) ;
FILES2READ = UPCASE( COMPRESS( 'K:\MALJIBOU\PAY'||PUT( DATE , MONYY5.)
||'.DAT' ) ) ;
OUTPUT ;
END ;
RUN ;
/* GET MONEY INFO FROM PAY FILES */
DATA CTSMONEY;
LENGTH FLAG $4.;
SET CTSPAY;
INFILE DUMMY FILEVAR = FILES2READ END = DONE ;
DO WHILE ( NOT DONE );
INPUT CONTID $9.
AMOUNT
ESTBGND $8.
ESTENDD $10.
ESTNUMB ;
FLAG='CIS';
YYMM = SUBSTR( PUT( ESTENDD , 6. -L ) , 1 , 4 ) ;
OUTPUT ;
END ;
RUN;
The file names read are named like:
PAYJUN06.DAT
PAYJUL06.DAT
PAYAUG06.DAT
PAYSEP06.DAT
PAYOCT06.DAT
PAYNOV06.DAT
PAYDEC06.DAT
PAYJAN07.DAT
PAYFEB07.DAT
PAYMAR07.DAT
Hope this may help.
On Wed, 5 Sep 2007 21:48:57 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Jason ,
>
>Skip the macro stuff and just pipe in your data set names from the
>directory. Do a search in the SAS-L archives for Pipe and your operating
>system (ie. windows or Unix).
>
>Toby Dunn
>
>From: "Dale, Jason - BLS" <Dale.Jason@BLS.GOV>
>Reply-To: "Dale, Jason - BLS" <Dale.Jason@BLS.GOV>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Double do loop inside macro
>Date: Wed, 5 Sep 2007 17:07:10 -0400
>
>Hello all. Here is my code:
>
>%macro cps(first_year=, last_year=, first_month=, last_month=);
>%do year = &first_year %to &last_year;
> %do month = &first_month %to &last_month;
> data cps&year&month;
> infile "C:\WINNT\Profiles\dale_j\My
>Documents\CPS\1994-1999\cpsb&year.&month..cpp"
> lrecl=1000
> missover;
> input PEMLR 180-181
> PEHRACT1 243-244
> PEHRACT2 245-246
> PEI01COW 432-433
> PEI02COW 442-443
> PEI01ICD 436-438
> PEI02ICD 446-448
> PWSSWGT 613-622
> PWORWGT 603-612;
> run;
> %end;
>%end;
>%mend cps;
>
>%cps(first_year=95, last_year=95, first_month=01, last_month=10);
>
>
>I am trying to read in monthly data sets. However, the input columns
>are only good for certain time periods (for example, September 1995 to
>December 1997). I can't seem to figure out how to begin my second loop
>on september and end on december, while keeping the loop bounded at 1
>and 12.... Example: 9, 10, 11, 12, 1, 2, 3, 4, ..., 10, 11, 12
>
>Hope this is clear.
>Jason Dale
>Bureau of Labor Statistics
>Office of Productivity and Technology
>Division of Industry Productivity Studies
>
>_________________________________________________________________
>Test your celebrity IQ. Play Red Carpet Reveal and earn great prizes!
>http://club.live.com/red_carpet_reveal.aspx?icid=redcarpet_hotmailtextlink2
|