PROC FORMAT

Last changed: 10 February 2021

To change the appearance of the variable entries in our data set  we can use a proc format step, there we can impose a new name on our entries A and B that describe the type of treatment.

Text format

is used if the variable entries are text, e.g. A and B. The difference to numeric formats is the $-sign.

proc format ;
value $treatmentnames
       "A" = "Standard treatment"
       "B" = "New treatment";
run;

 

 Explanation:

The value statement defines a new format. Here the format is called treatmentnames. It includes two formats: A will be called 'Standard treatment' and B will be called 'New treatment'.

The format effects output only if it is called upon, e.g. if we make a table:

Without formats:

proc freq data=indata2;
table type*date /nocol norow nopercent;
run;

With formats:

proc freq data=indata2;
table type*date /nocol norow nopercent;
format type $treatmentnames.;
run;

 

 Numeric format

is used if the variable entries are numerical. Assume we have a variable with entries 1-7 describing the day of week and we want to express this as text.

proc format library=formats;
value weekdayformat
      1= 'Sunday'
      2= 'Monday'
      3='Tuesday'
      4='Wednesday'
      5='Thursday'
      6='Friday'
      7='Saturday'
run;

 

 Further reading:

https://stats.idre.ucla.edu/sas/faq/how-can-i-change-the-way-variables-are-displayed-in-proc-freq/

PROC FORMAT: An Analyst’s Buddy : http://www2.sas.com/proceedings/sugi31/084-31.pdf

THE POWER OF PROC FORMAT: 

https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt3001.pdf

 

 


Contact