• Home
  • Profile
  • Papers
  • SAS programs

SAS programs
  • Write catalog content to text file
  • Create a document per format encountered
  • Dataset desciption of all dataset in the library
  • Effective questionnaire processing with Arrays
  • Proc transpose
  • Proc SQL where clause
  • Proc SQL dataset maintenance
  • Execute a macro with the value from a dataset observation
  • Change a format stored in the formats catalog
  • Create an empty dataset
Home Create a document per format encountered

Create a document per format encountered

[Download] [Print]
%******************************************************************************;
%** http://www.info-net.nl                                                   **;
%******************************************************************************;
%* Topic         : Reporting                                                  *;
%* Program       : Create a document per format encountered                   *;
%* Author        : Raymond Ebben                                              *;
%* Location      : http://www.info-net.nl/sas-programs/reporting              *;
%* Date          : April 2006                                                 *;
%* Version       : 1.0                                                        *;
%* Description   : This program creates a RTF (Word) document per format      *;
%*                 encountered. all these word document will be saved in the  *;
%*                 c:\formats\ directory Make sure this directory exists,     *;
%*                 or refer to an existing location                           *;
%******************************************************************************;
%* In datasets   : Library.formats                                            *;
%* In macrovars  : None                                                       *;
%* In files      : None                                                       *;
%* Out datasets  : None                                                       *;
%* Out macrovars : None                                                       *;
%* Out files     : c:\formats\&format..rtf                                    *;
%******************************************************************************;
%** Version control                                                          **;
%******************************************************************************;
%* Mod * Ver. * Date      *  Description                                      *;
%******************************************************************************;
%******************************************************************************;
 
%******************************************************************************;
%* Create a dataset from the formats.                                         *;
%******************************************************************************;
proc format library=library cntlout=work.fmt;
run;
 
%******************************************************************************;
%* Sort the data by format name.                                              *;
%******************************************************************************;
proc sort data=work.fmt;
  by fmtname;
run;
 
%******************************************************************************;
%* Markup the dataset for presentation                                        *;
%******************************************************************************;
data work.fmtnfo(keep=fmtname disp val label);
  length disp val fname $200 label $2000;
  set fmt;
  by fmtname;
  if first.fmtname then fmtst=1;
  if last.fmtname then fmtst=2;
  if type eq 'C' then do;
    fname='$'||left(trim(fmtname))||'.';
    disp='Value $'||left(trim(fmtname));
    if start=end then val='"'||left(trim(start))||'"';
    else val='"'||left(trim(start))||'" - "'||left(trim(end))||'"';
    label=quote(left(trim(label)));
  end;
  else do;
    fname=left(trim(fmtname))||'.';
    disp='Value '||left(trim(fmtname));
    if start=end then val=left(trim(start));
    else val=left(trim(start))||' - '||left(trim(end));
  end;
  if substr(fname,1,1) eq '$' then fmtname='_'||compress(fmtname);
run;
 
%******************************************************************************;
%* (re) sort the dataset for presentation                                     *;
%******************************************************************************;
proc sort data=work.fmtnfo;
  by fmtname;
run;
 
 
%******************************************************************************;
%* Create the RTF report                                                      *;
%******************************************************************************;
 
%macro ODScontents(format=);
  %****************************************************************************;
  %* Set the (ODS) output options                                             *;
  %****************************************************************************;
  options papersize=A4 nobyline nodate nonumber;
 
  title;
  footnote;
 
  ods listing close;
  ods escapechar='#';
  ods rtf author='info-net.nl'
          title='Formats overview'
          file="c:\formats\&format..rtf"
          startpage=never;
 
  %****************************************************************************;
  %* Print the report detail                                                  *;
  %****************************************************************************;
  proc report data=work.fmtnfo(where=(fmtname="&format"))
                   nowindows noheader missing split= "~" spacing= 1 ;
    column disp val label;
 
    define disp  / order   "Format" flow
                   style=[cellwidth=200 font_face='arial' font_size=8pt];
    define val   / display "Value"  flow
                   style=[cellwidth=200 font_face='arial' font_size=8pt];
    define label / display "label"  flow
                   style=[cellwidth=500 font_face='arial' font_size=8pt];
 
  run;
 
  %****************************************************************************;
  %* Close the ODS output options                                             *;
  %****************************************************************************;
  ods rtf close;
  ods listing;
 
%mend ODScontents;
 
 
%******************************************************************************;
%* Recursivly call the macro for each format encountered                      *;
%******************************************************************************;
data work.fmtnfo;
  set work.fmtnfo;
  by fmtname;
  if first.fmtname then
    call execute('%ODScontents(format='||compress(fmtname)||');');
run;
 
 
 
 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
 

© 2012 Raymond Ebben, expert SAS consultant and programmer, Netherlands All Rights Reserved.