• 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 Change a format stored in the formats catalog

Change a format stored in the formats catalog

[Download] [Print]
%******************************************************************************;
%** http://www.info-net.nl                                                   **;
%******************************************************************************;
%* Topic         : SAS Base                                                   *;
%* Program       : Change a format stored in the formats catalog              *;
%* Author        : Raymond Ebben                                              *;
%* Location      : http://www.info-net.nl/index/sas-coding/sas-base           *;
%* Date          : July 2006                                                  *;
%* Version       : 1.0                                                        *;
%* Description   : This program illustrates how to modify an existing         *;
%*                 user defined format straight from the formats catalog.     *;
%******************************************************************************;
%* In datasets   : None                                                       *;
%* In macrovars  : None                                                       *;
%* In files      : None                                                       *;
%* Out datasets  : None                                                       *;
%* Out macrovars : None                                                       *;
%* Out files     : None                                                       *;
%******************************************************************************;
%** Version control                                                          **;
%******************************************************************************;
%* Mod * Ver. * Date      *  Description                                      *;
%******************************************************************************;
%******************************************************************************;
 
%******************************************************************************;
%* First a user defined format is created to make sure the program has        *;
%* something to work with.                                                    *;
%* Typically this example would be used to change a format from a             *;
%* format catalog in a library that you do not control or want to change      *;
%******************************************************************************;
proc format library=work;
  value $greek      "A" = "ALPHA"
                    "B" = "BETA"
                    "G" = "GAMMA";
run;
 
%******************************************************************************;
%* Now this format will be changed to Title caps (first upcase, rest lowcase) *;
%* This will be done using the formats catalog to make sure the solution      *;
%* is dynamic, i.e. if the greek format is extended with, for instanse        *;
%* D for DELTA, the program will still work successfully on all values.       *;
%******************************************************************************;
 
%******************************************************************************;
%* First step is to output the formats catalog to a dataset. for performance  *;
%* reasons and to make sure nothing else is changed, only the greek format is *;
%* kept                                                                       *;
%******************************************************************************;
proc format library=work cntlout=work.fmt(where=(fmtname='GREEK'));
run;
 
%******************************************************************************;
%* Now the value will be changed to the required layout                       *;
%* (first upcase, rest lowcase)                                               *;
%******************************************************************************;
data work.fmt;
  set work.fmt;
  label=upcase(substr(label,1,1))||lowcase(substr(label,2));
 
  /* If you want to leave the original format in tact and create a new format,
     uncomment the line below and specify a format name for instance _greek */
  /*fmtname='_greek'; */
 
run;
 
%******************************************************************************;
%* The last step to update, or create a new format is to read in the          *;
%* dataset from the step above.                                               *;
%******************************************************************************;
proc format library=work cntlin=work.fmt;
run;
 
%******************************************************************************;
%* Finally, tidy up the workspace by removing the fmt work dataset which is   *;
%* not needed anymore.                                                        *;
%******************************************************************************;
proc datasets lib=work nolist;
  delete fmt;
quit;
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 

 

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