Previous Page | Next Page

The FORMAT Procedure

Example 5: Creating a Format from a Data Set


Procedure features:

PROC FORMAT statement option:

CNTLIN=

Input control data set

Data set:

WORK.POINTS, created from data lines in the sample code.


This example shows how to create a format from a SAS data set.

Tasks include the following:


Program

 Note about code
options nodate pageno=1 linesize=80 pagesize=60;
 Note about code
data scale;                                                                                                                             
   input begin $ 1-2 end $ 5-8 amount $ 10-12;                                                                                          
   datalines;                                                                                                                           
0   3    0%                                                                                                                             
4   6    3%                                                                                                                             
7   8    6%                                                                                                                             
9   10   8%                                                                                                                             
11  16   10%                                                                                                                            
;
 Note about code
data ctrl;
   length label $ 11;
 Note about code
   set scale(rename=(begin=start amount=label)) end=last;
 Note about code
   retain fmtname 'PercentageFormat' type 'n';
 Note about code
   output;
 Note about code
   if last then do;
      hlo='O';
      label='***ERROR***';
      output;
   end;
run;
 Note about code
proc print data=ctrl noobs;
 Note about code
   title 'The CTRL Data Set';
run;

 Note about figure
                               The CTRL Data Set                               1

         label          start    end        fmtname         type    hlo

         0%              0       3      PercentageFormat     n         
         3%              4       6      PercentageFormat     n         
         6%              7       8      PercentageFormat     n         
         8%              9       10     PercentageFormat     n         
         10%             11      16     PercentageFormat     n         
         ***ERROR***     11      16     PercentageFormat     n       O 
 Note about code
proc format library=work cntlin=ctrl;
run;
 Note about code
proc format;
   invalue evaluation 'O'=4
                      'S'=3
                      'E'=2
                      'C'=1
                      'N'=0;
run;
 Note about code
data points;
   input EmployeeId $ (Q1-Q4) (evaluation.,+1);
   TotalPoints=q1+q2+q3+q4;
   datalines;
2355 S O O S
5889 2 . 2 2
3878 C E E E
4409 0 1 1 1
3985 3 3 3 2
0740 S E E S
2398 E E   C
5162 C C C E
4421 3 2 2 2
7385 C C C N
;
 Note about code
proc report data=work.points nowd headskip split='#';
   column employeeid totalpoints totalpoints=Pctage;
   define employeeid / right;
   define totalpoints / 'Total#Points' right;
   define pctage / format=PercentageFormat12. 'Percentage' left;
   title 'The Percentage of Salary for Calculating Bonus';
run;

Output: Listing

                 The Percentage of Salary for Calculating Bonus                1

                       Employee      Total              
                             Id     Points  Percentage  
                                                        
                           2355         14  10%         
                           5889          .  ***ERROR*** 
                           3878          7  6%          
                           4409          3  0%          
                           3985         11  10%         
                           0740         10  8%          
                           2398          .  ***ERROR*** 
                           5162          5  3%          
                           4421          9  8%          
                           7385          3  0%          

Output: HTML

[untitled graphic]

Previous Page | Next Page | Top of Page