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

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!STACC.MED.UTAH.EDU!KNECHOD
  3. Mailer: Elm [revision: 66.33]
  4. Message-ID: <SAS-L%92073000530390@UGA.CC.UGA.EDU>
  5. Newsgroups: bit.listserv.sas-l
  6. Date:         Wed, 29 Jul 1992 22:56:52 MDT
  7. Reply-To:     knechod@stacc.med.utah.edu
  8. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  9. From:         Kevin Nechodom <knechod@STACC.MED.UTAH.EDU>
  10. Subject:      Re: Comma delimited output file from SAS on MVS/ESA
  11. Comments: To: SAS Mailing List <sas-l@uga.cc.uga.edu>
  12. In-Reply-To:  <DC.SYSD10.4662.1992 0729 12 34 12 34>; from "Pauline Sing" at
  13.               Jul 29, 92 12:35 (noon)
  14. Lines: 226
  15.  
  16. >
  17. > Hi Everyone,
  18. >
  19. > I am new to this list and I would appreciate any help if possible.
  20. >
  21. > I am trying to create a comma delimited flat file from SAS on an MVS machine.
  22. > I know that I could put a ',' between each variable but I have 600 variables
  23. > in 27 tables. I was wondering whether there is a shortcut? Any suggestions
  24. > would be greatly appreciated.
  25. >
  26. >                  Teale Data Center, State of California
  27. >                  Internet: DC.SYSD10@TS3.TEALE.CA.GOV
  28. >                  Address: P.O. Box 13436, Sacramento, Ca. 95813
  29. >                  phone: (916) 920-6568, atss 430-6568
  30. >
  31.  
  32. I have enclosed two macros here.  The first is the text of a posting
  33. by Ben Connor, who guided me in the right direction to Karen
  34. Patterson, who solved just this very problem.  The second is my
  35. rendition of a fax from Karen, with a couple of modifications.  1) I
  36. needed column headers, and 2) I changed the macro to accept the
  37. libref, filename, and output file.
  38.  
  39. Since I am NOT an IBM type of person, I have no idea about MVS, TSO,
  40. etc.  Therefore, I can give no guarantees that these will work.
  41. However, I have used it on an HP9000 HPUX machine using 6.07.02, and
  42. it has worked wonderfully, with one qualification.  It may only be a
  43. function of my ignorance, or a limitation of HPUX, but the file
  44. generated had a 256 character maximum length.  Since my data file had
  45. 74 variables, of which many were long character strings, the output of
  46. each data record was split into several output records.  Before I
  47. could import the data file in my spreadsheet EXCEL, I had to piece
  48. together each logical record.  That may, or may not, be a problem for
  49. you, and I'm hoping someone on the list will suggest a fix to that
  50. problem.
  51.  
  52. Finally, to voice an old complaint, it would be nice if the standard
  53. implementation of SAS included 'standard' (in quotes in deference to
  54. those who actually measure and evaluate such standards) file formats,
  55. like CSV, DBF, DIF, etc.  With the proliferation of UN*X workstations
  56. and the migratation of DOS programs like dBase to those workstations,
  57. the need is becoming greater!
  58.  
  59. Anyway, to continue ...
  60.  
  61. From SAS-L@uga.cc.uga.edu Tue Jun 16 11:01 MDT 1992
  62. Date:         Tue, 16 Jun 1992 09:56:00 PDT
  63. From: Ben Conner <bconner@NETCOM.COM>
  64. Subject:      Comma Delimited Files
  65.  
  66. > Based on the recent interest of Comma Delimited File formats, Karen Patterson
  67. > of San Diego Data Processing Corporation gave me permission to post this to
  68. > the list.  Hope it helps!
  69. >   --Ben Conner
  70. >   ---------------------------------------------------------------------------
  71. > Below is the sample SAS macro code on the last page of a paper presented by
  72. > Karen Patterson of San Diego Data Processing Corporation.  The paper was
  73.  titled
  74. > "Creating Comma-Delimited Files from SAS Data Sets for Downloading to Micro-
  75. > computers".  Hope it helps...
  76. >
  77. > SAMPLE SAS MACRO CODE
  78. >
  79. > LIBNAME SASIN 'TSOXXX.SAS.DATA' DISP=SHR;
  80. > FILENAME FLATOUT 'TSOXXX.SUGI17.FLATFILE' DISP=OLD REUSE;
  81. >
  82. > OPTIONS DQUOTE NOMPRINT NOMLOGIC NOMACROGEN NOSYMBOLGEN MISSING=' ';
  83. >
  84. > TITLE;
  85. >
  86. > %MACRO COMMA;
  87. > * ASSIGN LITERALS TO MACRO VARIABLES;
  88. > %LET LIBNAME=SASIN;
  89. > %LET MEMNAME=SUGI17;
  90. > %LET THEPUT=PUT;
  91. >
  92. > * SAVE CONTENTS OUTPUT IN A FILE;
  93. > PROC CONTENTS DATA=&LIBNAME..&MEMNAME  OUT=FILEDEF NOPRINT;
  94. >
  95. > * SORT BY THE VARIABLE NUMBER;
  96. > PROC SORT;
  97. >   BY VARNUM;
  98. >
  99. > * PUT MACRO VARIABLES IN SYMBOL TABLE;
  100. > DATA _NULL_;
  101. >   SET FILEDEF;
  102. >
  103. > * NUMBER OF VARIABLES;
  104. > CALL SYMPUT('NVAR',PUT(VARNUM,3.));
  105. >
  106. > * VARIABLE NAMES;
  107. > CALL SYMPUT('VNAME'||LEFT(PUT(_N_,3.)),PUT(NAME,$8.));
  108. >
  109. > * TYPE = 1 IS NUMERIC;
  110. > * TYPE = 2 IS CHARACTER;
  111. > IF TYPE = 1 THEN
  112. >   DO;
  113. >   IF FORMAT = 'MMDDYY' THEN
  114. >        CALL SYMPUT('TYPE'||LEFT(PUT(_N_,3.)),PUT("D",$1.));
  115. >     ELSE
  116. >        CALL SYMPUT('TYPE'||LEFT(PUT(_N_,3.)),PUT("N",$1.));
  117. >   END;
  118. > ELSE
  119. > IF TYPE = 2 THEN
  120. >   DO;
  121. >     CALL SYMPUT('TYPE'||LEFT(PUT(_N_,3.)),PUT("C",$1.));
  122. >   END;
  123. >
  124. > RUN;
  125. >
  126. > DATA _NULL_;
  127. >
  128. > * READ THE SAS DATASET;
  129. > SET &LIBNAME..&MEMNAME;
  130. >
  131. > * CREATE A FLAT TSO DATASET;
  132. > FILE FLATOUT;
  133. >
  134. > * POINTER VARIABLE TO MOVE COMMA BACK 1 COLUMN IN OUTPUT RECORD;
  135. > P = -1;
  136. >
  137. > * USE MACRO VARIABLES TO BUILD A PUT STATEMENT;
  138. >
  139. > IF _N_ = 1 THEN
  140. >   DO;
  141. >     %DO I = 1 %TO &NVAR;
  142. >        %IF "&&TYPE&I" = "D" OR
  143. >            "&&TYPE&I" = "C" %THEN
  144. >            %LET THEPUT = &THEPUT '"'&&VNAME&I +P '"' ',';
  145. >        %ELSE
  146. >            %LET THEPUT = %THEPUT &&VNAME&I +P ',';
  147. >         %END;
  148. >      END;
  149. >
  150. > * WRITE A COMMA DELIMITED RECORD;
  151. > &THEPUT;
  152. >
  153. > RUN;
  154. >
  155. > %MEND COMMA;
  156. >
  157. > %COMMA;
  158. >
  159.  -------------------------------------------------------------------------------
  160. > I've tried to be careful typing it in, but haven't had a chance to try it out
  161. > to make sure all is well.
  162. >    -Ben
  163. > Southern California Edison
  164. > (714) 368-8513
  165. >
  166.  
  167. And with modification, and remembering that I know almost nothing
  168. about SAS's macro language (or even what all these lines mean!):
  169.  
  170. %MACRO comma(lib,file,output);
  171.  
  172. filename SASOUT &output;
  173. options dquote nomprint nomlogic nomacrogen nosymbolgen
  174.   missing = ' ';
  175.  
  176. title;
  177.  
  178. %let THEPUT=PUT;
  179. %let HDRPUT=PUT;
  180.  
  181. proc contents data=&lib..&file out=filedef noprint;
  182. proc sort;
  183.   by varnum;
  184.  
  185. data _NULL_;
  186.   set filedef;
  187.  
  188. call symput('NVAR',put(varnum,3.));
  189.  
  190. call symput('VNAME'||left(put(_N_,3.)),put(name,$8.));
  191.  
  192. if type = 1 then
  193.   do;
  194.     if format="MMDDYY" then
  195.       call symput('TYPE'||left(put(_N_,3.)),put("D",$1.));
  196.     else
  197.       call symput('TYPE'||left(put(_N_,3.)),put("N",$1.));
  198.   end;
  199. else
  200. if type=2 then
  201.   do;
  202.     call symput('TYPE'||left(put(_N_,3.)),put("C",$1.));
  203.   end;
  204.  
  205. run;
  206.  
  207. data _NULL_;
  208.  
  209. set &lib..&file;
  210. file SASOUT;
  211.  
  212. p = -1;
  213.  
  214. if _N_ = 1 then
  215.   do;
  216.     %do i=1 %to &nvar;
  217.       %let HDRPUT = &HDRPUT '"' "&&VNAME&I" '"' ',';
  218.       %if "&&TYPE&I" = "D" or "&&TYPE&I"="C" %then
  219.         %let THEPUT = &THEPUT '"' &&VNAME&I+P '"' ',';
  220.       %else
  221.         %let THEPUT = &THEPUT &&VNAME&I + P ',';
  222.   %END;
  223. &HDRPUT;
  224. end;
  225.  
  226. &THEPUT;
  227.  
  228. run;
  229.  
  230. %MEND comma;
  231.  
  232. Sample run:
  233. %comma(prod,airheum,aiout)
  234.  
  235.  
  236.  
  237. --
  238. Kevin Nechodom UofU STACC        | Great Moments in Physics History:
  239.  UofU doesn't even know I exist; | "E= m c cubed?  No, too gaudy.
  240.  how would they care what I say? |  E= m c ?  No, too simple.
  241. knechod@stacc.med.utah.edu       |  E= m c squared?  Ah, ha!"
  242.