How Do I Build a Format from a Dataset?

  • Archive
  • SAS
This is one of our archive tips that we’ve kept as its still popular. Some of the information may be out of date. Get in touch if you need more help.

 

A very efficient way of defining Formats and Informats is to use an Input Control Data Set with Proc Format, rather than writing VALUE or INVALUE statements.

For example, suppose you have the following data set and you wish to create a simple numeric format to convert outlet codes into their actual names:

  Outcode  Outname
  101      Aberdeen
  102      Altrincham
  103      Ashford
  104      Barnsley
  105      Basildon
  106      Basingstoke
  107      BathFirst

Create the Input Control Data Set with the variables START, LABEL and FMTNAME. Then run a Proc Format step which points to the CNTLIN data set as follows.

Program: 

data work.outfmt(keep=start label fmtname);  
    set work.outlets(rename=(outcode=start outname=label));  
    fmtname='outfmt';
  run;
  proc format library=work cntlin=work.outfmt;
  run;

Log:

335  proc format library=work cntlin=work.outfmt;
NOTE: Format OUTFMT has been output.
336  run;

This technique is particularly useful when formats need to be created dynamically at run time.

Back to Insights

Talk to us about how we can help