You can easily generate a user-defined format if the values that you want to format are in Microsoft Excel.
The sample code on the Full Code tab uses Base SAS® to convert an Excel file to a SAS data set containing the three required variables for a control data set: FMTNAME, START, and LABEL. PROC FORMAT generates a format from the data set using the CNTLIN option. The START values obtained from the spreadsheet are grouped into age categories, and PROC REPORT is used to display the formatted results.
For another example of building a user-defined format from a SAS data set, see Example 11: Creating a Format from a Data Set in the Base SAS 9.4 Procedures Guide.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Create an Excel spreadsheet for the example. */
proc export data=sashelp.class outfile=test
dbms=xlsx outfile='c:\temp\exceltest.xlsx' replace;
run;
/* Read the Excel spreadsheet and create a SAS data set. */
proc import datafile='c:\temp\exceltest.xlsx' out=work.testfmt dbms=xlsx replace;
run;
/* Remove duplicate values */
proc sort data=testfmt nodupkey;
by age;
run;
/* Build control data set */
data new(rename=(age=start) keep=age fmtname label);
retain fmtname 'testfmt';
length label $8.;
set testfmt;
if age <= 12 then label='Pre-teen';
else if age ge 13 and age < 20 then label='Teen';
else label='Adult';
run;
/* Create the format using the control data set. */
proc format cntlin=new;
run;
/* Display average height by formatted values */
title;
ods listing close;
ods html file="c:\avgheight.htm" style=styles.sasweb;
proc report data=sashelp.class nowd split='/';
title 'Using Control Data Set to generate a format with Excel file';
col age height n;
define n / 'Count';
define age / group;
define height / mean 'Average Height /in Inches' f=6.2;
format age testfmt.;
run;
ods html close;
ods listing;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | Common Programming Tasks ==> Reading and Writing External Data ==> with PROC EXPORT Common Programming Tasks ==> Reading and Writing External Data ==> with PROC IMPORT Common Programming Tasks ==> Reading and Writing SAS Data Common Programming Tasks ==> Selecting Data Common Programming Tasks ==> Working with Character Data Common Programming Tasks |
Date Modified: | 2009-10-13 15:14:41 |
Date Created: | 2009-09-28 14:53:09 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | ||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Macintosh | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 8.1 Pro x64 | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |