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 (January 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 20 Jan 2006 08:06:03 -0600
Reply-To:   Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject:   Re: Reading like-named files sequentially into a data set
Comments:   To: rune@FASTLANE.NO
Content-Type:   text/plain; charset=ISO-8859-1

Rune:

Substitute midmon = monthnum - 1; lastmon = midmon - 1; with midmon = mod(monthnum - 1+12,12); lastmon = mod(midmon - 1+12,12);

J S Huang 1-515-557-3987 fax 1-515-557-2422

>>> Rune Runnestø <rune@FASTLANE.NO> 1/20/2006 7:47:14 AM >>> Hi, My files are named Month01 Month02 Month03 Month04 Month05 Month06 Month07 Month08 Month09 Month10 Month11 Month12

They contain data from their respective months (jan-des).

I am reading and concatenating the files for august, september and october with this code:

data work.LastQuarter (drop = i); do i = 8, 9, 10; nextfile="d:\sas_kode\k_sert_2\sasdata\route"||compress(put(i,2.)||".dat", ' '); do until(lastobs); infile temp filevar=nextfile end=lastobs; input RouteID $ 1-7 Origin $ 8-10 Dest $ 11-13 Distance 15-18 Fare1stclass 19-22 FareBusiness 23-26 FareCoach 27-30 FareCargo 35-35; output; end; end; stop; run;

This works fine, but I want to make the code more dynamic, and read the files for the last three months where the last month is this month. So I thougth to do it this way:

data work.LastQuarter (drop = monthnum midmon lastmon); monthnum = month(today()); midmon = monthnum - 1; lastmon = midmon - 1; do i = monthnum, midmon, lastmon; nextfile="d:\sas_kode\k_sert_2\sasdata\route"||compress(put(i,2.)||".dat", ' '); do until(lastobs); infile temp filevar=nextfile end=lastobs; input RouteID $ 1-7 Origin $ 8-10 Dest $ 11-13 Distance 15-18 Fare1stclass 19-22 FareBusiness 23-26 FareCoach 27-30 FareCargo 35-35; output; end; end; stop; run;

But this doesn't work. Cause now we are in january, and monthnum = 1. But with this code, midmon = 0 and lastmon = -1. Any suggestions how to get the right values, whenever during the year the code is submitted ?

Rune


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