home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / bit / listserv / sasl / 3469 < prev    next >
Encoding:
Text File  |  1992-07-29  |  6.0 KB  |  228 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!OSI.OHIO.GOV!MR_CA_CBU
  3. Message-ID: <SAS-L%92072913323763@UGA.CC.UGA.EDU>
  4. Newsgroups: bit.listserv.sas-l
  5. Date:         Wed, 29 Jul 1992 13:35:00 EST
  6. Reply-To:     MR_CA_CBU@OSI.OHIO.GOV
  7. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  8. From:         MR_CA_CBU@OSI.OHIO.GOV
  9. Subject:      re: inserting file dates in footer etc
  10. Comments: To: SAS-L <SAS-L@UGA.CC.UGA.EDU>
  11. Lines: 215
  12.  
  13.      CONTENT:  reply to file dates in footer
  14.      SUMMARY:  one technique to use external file to get file dates of
  15.                 said files
  16.      REL/PLTF: 6.07 / VAX/VMS
  17.      E-ADDR:   MR_CA_CBU@OSI.OHIO.GOV
  18.      NAME:     Carleton Underwood
  19.      AGENCY:   Ohio Dept Mental Retardation/Developmental Disabilities
  20.      PH/ADDR:  (614) 439-1371 W/(614) 454-0881 H / Cambridge, Ohio 43725
  21.  
  22.  
  23. Marc Schaeffer asks -
  24.  
  25. I use SAS 6.07 under VMS.  My data sets are files, in SAS dataset
  26. form, extracted from an on-line student information system.  The
  27. extracts are not dynamic files in that they are refreshed on a regular
  28. schedule (some nightly, some weekly).  Question: Is there a macro,
  29. like &sysdate, which I can use to insert the filedate (i.e., the date
  30. the file was last refreshed) in a footer in my reports?
  31.  
  32. Since you're using VMS, the concepts presented below *should* translate
  33. directly.
  34.  
  35. Below find a rather complex SAS program that uses the VMS DIR command to get
  36. a listing of files, select the most up-to-date one(s), store the results
  37. in a text file, creates s 20/20 (Access Technology's spreadsheet) macro
  38. file and exits.
  39.  
  40. Hope it is helpful
  41.  
  42. Carl
  43. MR_CA_CBU@OSI.OHIO.GOV
  44. ------------------------------cut here-----------------------------------
  45. /* file to be run from Account having MR_DCRREPTS PROCESS RIGHTS ID
  46.    to create a 20/20 command (macro) file to find all the files to
  47.    print for the DEVELOPMENTAL CENTERs fiscal reports
  48.  
  49. first draft 20-may-1992 2:30pm cbu
  50. second draft 21-may-1992
  51.  
  52. In the directory from which it is run, these text files are created:
  53.  
  54. FISCAL.TXT
  55. DATES.TXT
  56.  
  57. The files with the TXT extension may be deleted by you after the
  58. program runs.
  59.  
  60. FISCAL_REPORTS.C20
  61.  
  62. The file with the C20 extension is the 20/20 command file.
  63. When run, it will create files called YYAAAAAA.PRT where YY = YEAR
  64. and AAAAAA = rest of filename. PRT is the default 20/20 print file
  65. extension.
  66.  
  67. You should make sure you do not have any 20/20 print files in your
  68. directory before running this program, because it will delete them.
  69.  
  70. Any questions or bug reports should be directed to:
  71.  
  72. Carleton B. Underwood, Systems Analyst
  73. Cambridge Developmental Center
  74.  
  75. (614) 439-1371 or (614) 454-0881 - no collect calls please
  76. FAX Number: (614) 439-4382
  77.  
  78. May 21, 1992                                                 */
  79.  
  80. libname c '[]';
  81. filename mac '[]fiscal_reports.c20';
  82. filename fiscal '[]fiscal.txt';
  83. filename dates '[]dates.txt';
  84.  
  85. %let yr = 93 ; /* change as needed */
  86. %let fyr = 1992 ; /* full year */
  87.  
  88. /* options to debug macros */
  89. options symbolgen mprint mlogic;
  90. run;
  91.  
  92. /* delete outstanding 20/20 print files starting with YR */
  93.  
  94. x "delete &YR*.PRT;*";
  95. run;
  96.  
  97. /* create a text file with filenames and modified dates in it
  98.    Then process with a series of SAS datasteps */
  99.  
  100.  x "dir
  101.  mr_dcrrepts:&YR*.w20/col=1/ver=1/out=dates.txt/date=modified/noheader/notrail";
  102.  run;
  103.  
  104. /* the date you use to limit the directory listing is created below */
  105.  
  106. data lastdate;
  107. length line $ 47;
  108. length dates $ 11 ;
  109. length moddate 8. ;
  110. format moddate date9. ;
  111.  
  112. infile dates missover;
  113.  
  114. input line $ 1-45 @ ;
  115.  
  116. if substr(line,34,3)="]&YR" then do;
  117. input #2 dates $ 22-32 #2;
  118. moddate = input(dates,date11.);
  119. end;
  120. else input #2 ;
  121. keep moddate ;
  122. run;
  123.  
  124. proc sort data=lastdate nodup;
  125. by descending moddate ;
  126. run;
  127.  
  128. /* find the start limit - a 2 step process */
  129. data limit ;
  130. retain x xx ;
  131. format since x xx date9.;
  132. length since2 s $ 11 ;
  133.  
  134. set lastdate end=final;
  135.  
  136. /* latest date modified */
  137. if _n_ = 1 then
  138. x = moddate ;
  139.  
  140. /* next to the latest date modified */
  141. else if _n_ = 2 then do;
  142. xx = moddate ;
  143.  
  144. /* only 1 day apart - use next to the latest date modified */
  145. if x-xx = 1 then do;
  146. since = xx ;
  147. end;
  148.  
  149. /* oops - caught the first batch of modified files - use latest date */
  150. else if x-xx > 1 then since = x ;
  151. end;
  152.  
  153. /* boil it down to 1 record */
  154. if since = . then delete;  /* get rid of empty records */
  155.  
  156. /* format the date into DD-MMM-YYYY that VMS likes to see */
  157. s = put(since,date9.);
  158. s = trim(s);
  159. since2 = substr(s,1,2) || '-' || substr(s,3,3) || '-' || substr(s,6,4) ;
  160.  
  161. run;
  162.  
  163. data x;
  164. set limit ;
  165.  
  166. /* if we're on the last record - then create a macro variable
  167.    for the /SINCE= switch                                     */
  168.  
  169. if _n_ = 1 then call SYMPUT('SLIMIT',SINCE2);
  170. run;
  171.  
  172. /* create a text file to use as an input file to create the 20/20
  173.    macro in later datasteps - uses slimit macro variable as startlimit */
  174.  
  175.  x "dir mr_dcrrepts:&YR*.w20/col=1/ver=1/out=fiscal.txt/since=&slimit" ;
  176.  run;
  177.  
  178. /* read the file called fiscal.txt to get the filenames */
  179. data files;
  180. infile fiscal missover;
  181. input filename $ ;
  182.  
  183. /* get rid of records that say directory, total, or are blank */
  184.  
  185. if substr(UPCASE(filename),1,2) = 'DI' then delete;
  186. if substr(UPCASE(filename),1,2) = 'TO' then delete;
  187. if length(filename) < 2 then delete;
  188.  
  189. run;
  190.  
  191. /* finally - the datastep that writes out the 20/20 macro file */
  192.  
  193. data _null_;
  194.  
  195. file mac;
  196.  
  197. length prtfile $30. ;
  198. length getfile $30. ;
  199.  
  200. set files end=eof ;
  201.  
  202. if _n_=1 then do;
  203. put @1 "! macro created for 2020 on &sysdate &systime with SAS &sysver";
  204. put @1 "! Based on an idea and need by Carl Underwood, Camb DevC - May 1992 ";
  205. put @1 "! Set the FILEPREFIX to MR_DCRREPTS: ";
  206. put @1 "/sffmr_dcrrepts:#/";
  207. put @1 "! ";
  208. put @1 "! Execute the GETFILE and PRTFILE until we run out of SAS records";
  209. end;
  210.  
  211. /* compose the proper syntax for 20/20 */
  212. getfile = '/sr' || filename || '*#list#;#/';
  213. prtfile = '/pf' || filename || '#/#/';
  214.  
  215. put @1 getfile ;
  216. put @1 prtfile ;
  217.  
  218. /* if out of SAS records, then write out the 20/20 quit sequence */
  219.  
  220. if eof then do;
  221. put @1 "! Done with printing files - execute quit";
  222. put @1 '/qy';
  223. end;
  224.  
  225. run;
  226.  
  227. /* end of program */
  228.