home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!paladin.american.edu!auvm!OSI.OHIO.GOV!MR_CA_CBU
- Message-ID: <SAS-L%92072913323763@UGA.CC.UGA.EDU>
- Newsgroups: bit.listserv.sas-l
- Date: Wed, 29 Jul 1992 13:35:00 EST
- Reply-To: MR_CA_CBU@OSI.OHIO.GOV
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: MR_CA_CBU@OSI.OHIO.GOV
- Subject: re: inserting file dates in footer etc
- Comments: To: SAS-L <SAS-L@UGA.CC.UGA.EDU>
- Lines: 215
-
- CONTENT: reply to file dates in footer
- SUMMARY: one technique to use external file to get file dates of
- said files
- REL/PLTF: 6.07 / VAX/VMS
- E-ADDR: MR_CA_CBU@OSI.OHIO.GOV
- NAME: Carleton Underwood
- AGENCY: Ohio Dept Mental Retardation/Developmental Disabilities
- PH/ADDR: (614) 439-1371 W/(614) 454-0881 H / Cambridge, Ohio 43725
-
-
- Marc Schaeffer asks -
-
- I use SAS 6.07 under VMS. My data sets are files, in SAS dataset
- form, extracted from an on-line student information system. The
- extracts are not dynamic files in that they are refreshed on a regular
- schedule (some nightly, some weekly). Question: Is there a macro,
- like &sysdate, which I can use to insert the filedate (i.e., the date
- the file was last refreshed) in a footer in my reports?
-
- Since you're using VMS, the concepts presented below *should* translate
- directly.
-
- Below find a rather complex SAS program that uses the VMS DIR command to get
- a listing of files, select the most up-to-date one(s), store the results
- in a text file, creates s 20/20 (Access Technology's spreadsheet) macro
- file and exits.
-
- Hope it is helpful
-
- Carl
- MR_CA_CBU@OSI.OHIO.GOV
- ------------------------------cut here-----------------------------------
- /* file to be run from Account having MR_DCRREPTS PROCESS RIGHTS ID
- to create a 20/20 command (macro) file to find all the files to
- print for the DEVELOPMENTAL CENTERs fiscal reports
-
- first draft 20-may-1992 2:30pm cbu
- second draft 21-may-1992
-
- In the directory from which it is run, these text files are created:
-
- FISCAL.TXT
- DATES.TXT
-
- The files with the TXT extension may be deleted by you after the
- program runs.
-
- FISCAL_REPORTS.C20
-
- The file with the C20 extension is the 20/20 command file.
- When run, it will create files called YYAAAAAA.PRT where YY = YEAR
- and AAAAAA = rest of filename. PRT is the default 20/20 print file
- extension.
-
- You should make sure you do not have any 20/20 print files in your
- directory before running this program, because it will delete them.
-
- Any questions or bug reports should be directed to:
-
- Carleton B. Underwood, Systems Analyst
- Cambridge Developmental Center
-
- (614) 439-1371 or (614) 454-0881 - no collect calls please
- FAX Number: (614) 439-4382
-
- May 21, 1992 */
-
- libname c '[]';
- filename mac '[]fiscal_reports.c20';
- filename fiscal '[]fiscal.txt';
- filename dates '[]dates.txt';
-
- %let yr = 93 ; /* change as needed */
- %let fyr = 1992 ; /* full year */
-
- /* options to debug macros */
- options symbolgen mprint mlogic;
- run;
-
- /* delete outstanding 20/20 print files starting with YR */
-
- x "delete &YR*.PRT;*";
- run;
-
- /* create a text file with filenames and modified dates in it
- Then process with a series of SAS datasteps */
-
- x "dir
- mr_dcrrepts:&YR*.w20/col=1/ver=1/out=dates.txt/date=modified/noheader/notrail";
- run;
-
- /* the date you use to limit the directory listing is created below */
-
- data lastdate;
- length line $ 47;
- length dates $ 11 ;
- length moddate 8. ;
- format moddate date9. ;
-
- infile dates missover;
-
- input line $ 1-45 @ ;
-
- if substr(line,34,3)="]&YR" then do;
- input #2 dates $ 22-32 #2;
- moddate = input(dates,date11.);
- end;
- else input #2 ;
- keep moddate ;
- run;
-
- proc sort data=lastdate nodup;
- by descending moddate ;
- run;
-
- /* find the start limit - a 2 step process */
- data limit ;
- retain x xx ;
- format since x xx date9.;
- length since2 s $ 11 ;
-
- set lastdate end=final;
-
- /* latest date modified */
- if _n_ = 1 then
- x = moddate ;
-
- /* next to the latest date modified */
- else if _n_ = 2 then do;
- xx = moddate ;
-
- /* only 1 day apart - use next to the latest date modified */
- if x-xx = 1 then do;
- since = xx ;
- end;
-
- /* oops - caught the first batch of modified files - use latest date */
- else if x-xx > 1 then since = x ;
- end;
-
- /* boil it down to 1 record */
- if since = . then delete; /* get rid of empty records */
-
- /* format the date into DD-MMM-YYYY that VMS likes to see */
- s = put(since,date9.);
- s = trim(s);
- since2 = substr(s,1,2) || '-' || substr(s,3,3) || '-' || substr(s,6,4) ;
-
- run;
-
- data x;
- set limit ;
-
- /* if we're on the last record - then create a macro variable
- for the /SINCE= switch */
-
- if _n_ = 1 then call SYMPUT('SLIMIT',SINCE2);
- run;
-
- /* create a text file to use as an input file to create the 20/20
- macro in later datasteps - uses slimit macro variable as startlimit */
-
- x "dir mr_dcrrepts:&YR*.w20/col=1/ver=1/out=fiscal.txt/since=&slimit" ;
- run;
-
- /* read the file called fiscal.txt to get the filenames */
- data files;
- infile fiscal missover;
- input filename $ ;
-
- /* get rid of records that say directory, total, or are blank */
-
- if substr(UPCASE(filename),1,2) = 'DI' then delete;
- if substr(UPCASE(filename),1,2) = 'TO' then delete;
- if length(filename) < 2 then delete;
-
- run;
-
- /* finally - the datastep that writes out the 20/20 macro file */
-
- data _null_;
-
- file mac;
-
- length prtfile $30. ;
- length getfile $30. ;
-
- set files end=eof ;
-
- if _n_=1 then do;
- put @1 "! macro created for 2020 on &sysdate &systime with SAS &sysver";
- put @1 "! Based on an idea and need by Carl Underwood, Camb DevC - May 1992 ";
- put @1 "! Set the FILEPREFIX to MR_DCRREPTS: ";
- put @1 "/sffmr_dcrrepts:#/";
- put @1 "! ";
- put @1 "! Execute the GETFILE and PRTFILE until we run out of SAS records";
- end;
-
- /* compose the proper syntax for 20/20 */
- getfile = '/sr' || filename || '*#list#;#/';
- prtfile = '/pf' || filename || '#/#/';
-
- put @1 getfile ;
- put @1 prtfile ;
-
- /* if out of SAS records, then write out the 20/20 quit sequence */
-
- if eof then do;
- put @1 "! Done with printing files - execute quit";
- put @1 '/qy';
- end;
-
- run;
-
- /* end of program */
-