Chapter Contents |
Previous |
Next |
SAS Procedures Guide |
Input Data Sets |
proc print data=emp;
If you omit the DATA= option, the procedure uses the value of the SAS system option _LAST_=. The default of _LAST_= is the most recently created SAS data set in the current SAS job or session. _LAST_= is described in detail in SAS Language Reference: Dictionary.
Output Delivery System |
Beginning with Version 7, procedure output became much more flexible. The Output Delivery System (ODS) has been designed to overcome the limitations of traditional SAS output and to make it easy to make new formatting options available to users. ODS is a method of delivering output in a variety of formats and of making the formatted output easy to access. Important features of ODS include the following:
In addition, ODS removes responsibility for formatting output from individual procedures and from the DATA step. The procedure or DATA step supplies raw data and the name of the table definition that contains the formatting instructions, and ODS formats the output. Because formatting is now centralized in ODS, the addition of a new ODS destination does not affect any procedures or the DATA step. As future destinations are added to ODS, they will automatically become available to all procedures that support ODS and to the DATA step.
This section briefly illustrates these features. For more information about the Output Delivery System, see The Complete Guide to the SAS Output Delivery System.
Note: The examples in this section use filenames that may not be valid
in all operating environments. To successfully run the example in your operating
environment, you may need to change the file specifications. See Appendix
1, "Alternate ODS HTML Statements for Running Examples in Different
Operating Environments," in The Complete Guide to the SAS Output Delivery System.
odsprinter.ps
. The second ODS PRINTER
statement closes the Printer destination. You must close the Printer destination
before you can print the file.
The data set STATEPOP is created in a DATA step . The REGFMT. format is created in a PROC FORMAT step . The printer output appears in Output Created by the Printer Destination .
options nodate nonumber; ods printer file='odsprinter.ps'; proc tabulate data=statepop; class region state; var citypop_80 citypop_90; table region*state, citypop_80*sum=' ' citypop_90*sum=' '; format region regfmt.; where region=1; label citypop_80='1980' citypop_90='1990'; title 'Metropolitan Population for the Northeast Region'; title2 '(measured in millions)'; run; ods printer close;
Output Created by the Printer Destination
The ODS HTML statement, which generates the HTML files, can create
For example, the first ODS HTML statement in the following SAS program generates four HTML files. ODS routes the results of the PROC UNIVARIATE step to the body file as well as to the Listing destination. ODS also creates the associated contents, page, and frame files. The second ODS HTML statement closes the HTML destination. You must close the HTML destination before you can browse the HTML files.
/* Create HTML files. */ ods html file='odshtml-body.htm' contents='odshtml-contents.htm' page='odshtml-page.htm' frame='ods-html-frame.htm';
proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; title; run;
/* Close the HTML destination. */ /* You must close this destination before */ /* you can browse the HTML files. */ ods html close;
Frame File Created by the ODS HTML Statement.
Select an entry in the table of contents to see the corresponding procedure results. |
Note: Procedure options that affect presentation may not affect HTML output.
For instance, the DOUBLE option in PROC PRINT, which inserts a blank line
between observations, has no effect on HTML output.
ods trace on;As long as the tracing feature is on, information about each output object that is created appears in the SAS log.
Use this statement to stop sending the information to the log:
ods trace off;
For example, the following SAS program produces the SAS log that is shown in SAS Log Produced by the ODS TRACE Statement :
options nodate pageno=1 linesize=64 pagesize=60; ods trace on; proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; title; run; ods trace off;SAS Log Produced by the ODS TRACE Statement
If you compare this SAS log to the Results Folder that appears in View of the Results Folder , you can see that the string that identifies the output in the Results folder is its label.
For more information about the trace record, see the discussion of the
contents of the trace record in the documentation for the ODS TRACE statement
in "The ODS Statements" in The Complete Guide to the SAS Output Delivery System.
You choose the objects to send to destinations with the ODS SELECT or the ODS EXCLUDE statement. To select individual output objects, use this form of the ODS SELECT statement:
ODS SELECT selection(s); |
For example, to select just the output objects that contain the basic measures and the quantiles from the PROC UNIVARIATE output, use the following program.
/* Create HTML files. */ ods html file='select-body.htm' contents='select-contents.htm' page='select-page.htm' frame='select-frame.htm';
/* Select output objects by name. */ ods select BasicMeasures Quantiles; /* Analyze the data. */ proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; title; run; /* Close the HTML destination. */ ods html close;The frame file appears in Frame File for Selected Output Objects . The program also creates Listing output, which is not shown. The Listing output contains the same information as the HTML body file, but it is formatted with the traditional SAS monospace font.
Frame File for Selected Output Objects
The contents file shows that for each variable in the analysis, PROC UNIVARIATE produces two output objects: one that contains basic measures and one that contains quantiles. All four output objects are in the body file because the ODS SELECT statement used names to identify the objects. If the ODS SELECT statement had used paths, which are unique, it could have selected output objects for the individual variables. |
To create a data set, use the ODS OUTPUT statement. In this statement, you identify
ODS OUTPUT output-object=SAS-data-set; |
Specify the output object as you do in the ODS SELECT statement: with a path, a name, a label, or a partial path. For example, to generate and print an output data set from each output object that contains the basic measures that PROC UNIVARIATE produces, use the following SAS program.
/* Turn off the generation of Listing output */ /* because you want to create a data set, not */ /* see the results. */ ods listing close; /* Specify the data set to create. */ ods output BasicMeasures=measures; /* When PROC UNIVARIATE runs, ODS */ /* creates a data set named MEASURES */ /* from the output object named */ /* BasicMeasures. */ proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; title; run;
/* Open the HTML destination for PROC PRINT. */ ods html body='measures-body.htm' contents='measures-contents.htm' frame='measures-frame.htm';
/* Print the output data set. */ proc print data=measures noobs headings=horizontal; title 'Output Data Set Produced from'; title2 'PROC UNIVARIATE Basic Measures'; run; /* Reset the destinations to their defaults. */ /* Close the HTML destination. */ ods html close; /* Open the Listing destination. */ ods listing;
You can use the resulting data set as input to another SAS program. This program simply prints the data set to illustrate its structure. The HTML output from PROC PRINT appears in PROC PRINT Report of the Data Set Created by PROC UNIVARIATE and ODS .
PROC PRINT Report of the Data Set Created by PROC UNIVARIATE and ODS
The data set contains observations for each of the variables in the VAR statement in PROC UNIVARIATE. |
Consider the following SAS program, which generates Listing, HTML, and Printer output as well as an output data set (Output output). The data set STATEPOP contains information about the distribution of the United States' population in metropolitan and nonmetropolitan areas for 1980 and 1990. A DATA step creates this data set.
options nodate pageno=1 linesize=80 pagesize=34;
ods html file='results-body.htm'; ods printer file='results.ps'; ods output basicmeasures=measures;
proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; title; run;
ods html close; ods printer close;The Results folder (see View of the Results Folder ) shows the folders and output objects that the procedure produces.
For example, the following SAS program creates a customized table definition for the BasicMeasures output object from PROC UNIVARIATE. (The trace record provides the name of the table definition that each object uses. See SAS Log Produced by the ODS TRACE Statement .) In the customized version
/* These four options all affect the Listing output. */ /* NODATE and NONUMBER also affect the Printer output.*/ /* None of them affects the HTML output. */ options nodate nonumber linesize=80 pagesize=60;
/* This PROC TEMPLATE step creates a table definition */ /* base.univariate.Measures in the SASUSER template */ /* store. Table definitions that are provided */ /* by SAS Institute are stored in a template */ /* store in the SASHELP library. By default, ODS */ /* searches for a table definition in SASUSER before */ /* SASHELP, so when PROC UNIVARIATE calls for a */ /* table definition by this name, ODS uses the one */ /* from SASUSER. */ proc template; define table base.univariate.Measures; notes "Basic measures of location and variability"; translate _val_ = ._ into '';
/* The HEADER statement determines the order */ /* in which the table definition uses the */ /* headers, which are defined later. */ header h1 h2 h3; /* The COLUMN statement determines the order */ /* in which the variables appear. PROC */ /* UNIVARIATE names the variables. */ column VarMeasure VarValue LocMeasure LocValue;
/* These DEFINE blocks define the headers. */ /* They specify the text for each header. By */ /* default, a header spans all columns, so */ /* H1 does so. H2 spans the variables */ /* VarMeasure and VarValue. H3 spans */ /* LocMeasure and LocValue. */ define h1; text "Basic Statistical Measures"; spill_margin=on; space=1; end; define h2; text "Measures of Variability"; start=VarMeasure end=VarValue; end; define h3; text "Measures of Location"; start=LocMeasure end=LocValue; end;
/* These DEFINE blocks specify characteristics */ /* for each of the variables. There are two */ /* differences between these DEFINE blocks and */ /* the ones in the table definition in SASHELP. */ /* These blocks use FORMAT= to specify a format */ /* of 7.3 for LocValue and VarValue. They also */ /* use STYLE= to specify a bold, italic font */ /* for these two variables. The STYLE= option */ /* does not affect the Listing output. */ define LocMeasure; print_headers=off; glue=2; space=3; style=rowheader; end; define LocValue; print_headers=off; space=5; format=7.3; style=data{font_style=italic font_weight=bold}; end; define VarMeasure; print_headers=off; glue=2; space=3; style=rowheader; end; define VarValue; print_headers=off; format=7.3; style=data{font_style=italic font_weight=bold}; end;
/* End the table definition. */ end; /* Run the procedure. */ run;
/* Begin the program that uses the */ /* customized table definition. */ /* The ODS HTML statement opens the HTML */ /* destination and identifies the files to */ /* write to. */ ods html file='statepop-body.htm' contents='statepop-contents.htm' page='statepop-page.htm' frame='statepop-frame.htm'; /* The ODS PRINTER statement opens the */ /* Printer destination and identifies the */ /* file to write to. */ ods printer file='statepop.ps';
/* The ODS SELECT statement selects just the */ /* output object that contains the basic measures. */ ods select BasicMeasures; /* PROC UNIVARIATE produces one object for each */ /* variable. It uses the customized table */ /* definition to format the data because the */ /* customized definition is in SASUSER. (See the */ /* explanation with the PROC TEMPLATE statement in */ /* this example. */ title; proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; run; /* Close the HTML destination. */ ods html close; /* Close the Printer destination. */ ods printer close;
Customized Listing Output from PROC UNIVARIATE
Customized Printer Output from PROC UNIVARIATE (page 1)
Customized Printer Output from PROC UNIVARIATE (page 2)
A Gallery of HTML and Printer Output Produced by Base Procedures |
ods html body='external-file';
If Printer output is shown, the specified example was run with this ODS PRINTER statement preceding it:
ods printer file='external-file';You must execute the following statement before you can view the resulting HTML files in a browser:
ods html close;You must execute the following statement before you can print Printer output:
ods printer close;
HTML Output from PROC TABULATE
Printer Output from PROC TABULATE
Printer Output from PROC FREQ (page 1)
Printer Output from PROC FREQ (page 2)
Customizing the Style Definition That ODS Uses |
For a list of the attributes, see What Style Attributes Can Base Procedures Specify? .
View | Results |
Sashelp.tmplmst
.
Styles
, and use your right
mouse button to open this folder, which contains a list of available style
definitions. If you want to view the underlying SAS code for a style definition,
select it and open it.
Operating Environment Information: For information on navigating in the Explorer window without a mouse, see the section on "Window Controls and General Navigation" in the SAS documentation for your operating environment.
You can also, submit this PROC TEMPLATE step to see the SAS code for a style definition:
proc template; source style-name; run;where style-name is the path to the style from the template store (for example
styles.default
or styles.beige
).
The HTML destination uses the style that is called Default
unless you specify an alternative style with the
STYLE= option
in the ODS HTML statement (see the documentation for the ODS HTML statement
in The Complete Guide to the SAS Output Delivery System). The Printer destination uses the style that is called Printer
unless you specify an
alternative style with the STYLE=
option in the ODS PRINTER statement (see the documentation for the ODS PRINTER
statement in The Complete Guide to the SAS Output Delivery System).
In most cases, if you want to alter the style of a file that ODS produces,
you must make a copy of the style that is used, alter that copy, and store
it so that ODS will find it and use it before it finds the style that SAS
Institute provides. (For information on this process, see The Complete Guide to the SAS Output Delivery System.)
However, procedures that build reports that are based on information
that the user provides do not use the same templates. Two of these procedures,
PROC REPORT and PROC TABULATE, provide a way for you to customize the HTML
and Printer output directly from the PROC step that creates the report. Information
on how to do this is provided with the syntax for these procedures.
Note: The default value that is used for an attribute depends on the
style definition that is in use. For information on viewing the attributes
in a style, see What Style Definitions Are Shipped with the Software? .
The implementation of an attribute depends on the ODS destination that formats
the output. In addition, if you are creating HTML output, the implementation
of an attribute depends on the browser that you use.
Many values for style attributes are one of the following:
cm | centimeters |
in | inches |
mm | millimeters |
pt | a printer's point |
px | pixels (based on the size of a pixel on the target device) |
Note: In Version 8 of the SAS
System, only the Printer
destination supports units of measure on dimensions. However, if you specify
CSS in the ODS HTML statement, the HTML destination supports units of measure.
The CSS option is experimental in Version 8.
Default: | For the HTML destination, pixels; for the Printer destination, units of 1/150 of an inch |
DMSBLUE | DMSBLACK |
DMSRED | DMSMAGENTA |
DMSPINK | DMSGRAY |
DMSGREEN | DMSBROWN |
DMSCYAN | SYSBACK |
DMSYELLOW | SYSSECB |
DMSWHITE | SYSFORE |
DMSORANGE |
Note: Use
these colors only if you are
running SAS in
the windowing environment.
Lightness | Saturation | Hue |
---|---|---|
black | gray | blue |
very dark | grayish | purple |
dark | moderate | red |
medium | strong | orange | brown |
light | vivid | yellow |
very light | green | |
white |
You can combine these words to form a wide variety of colors. Some examples are
light vivid green | |
dark vivid orange | |
light yellow |
Note: The
Output Delivery system first tries to match
a color with a SAS/GRAPH color. Thus, although brown and orange are interchangeable
in the table, if you use them as unmodified hues, they are different. The
reason for this is that ODS treats them like SAS colors, which are mapped
to different colors.
You can also specify hues that are intermediate between two neighboring colors. To do so, combine one of the following adjectives with one of its neighboring colors:
reddish |
orangish |
brownish |
yellowish |
greenish |
bluish |
purplish |
bluish purple (which is the same as purplish blue) | |
reddish orange | |
yellowish green |
See also: | For information on SAS/GRAPH colors, see SAS/GRAPH Software: Reference. |
style datacell / background=blue foreground=white;
Later, you can ensure that another style element, NEWCELL, uses the same background color by defining it this way:
style newcell / background=datacell(background);
Similarly, suppose that you create a style element called HIGHLIGHTING that defines three attributes this way:
style highlighting / "go"=green "caution"=yellow "stop"=red;Later, you can define a style element called MESSAGES that uses the colors that are defined in HIGHLIGHTING:
style messages; "note"=highlighting("go") "warning"=highlighting("caution") "error"=highlighting("stop");In this way, multiple style elements could use the colors that you define in HIGHLIGHTING. If you decide to change the value of
"go"
to blue, you
simply change its value in the definition of HIGHLIGHTING, and every style
element that references highlighting ("go") will use blue instead
of green.
Note: In the first example, the style attribute BACKGROUND= is
a predefined style attribute. Therefore, when you reference it, you do not
put it in quotation marks. However, in the second example, "go"
is a user-defined attribute. You define it
with quotation marks, and when you reference it, you must use quotation marks.
(This section describes all the predefined style attributes that are available.)
You can use a special form of reference to get a value for a style attribute
from the macro table at the time that the style element is used. For instance,
the following STYLE statement uses the current value of the macro variable bkgr
for the background color of the style element cell
:
style cell / background=symget("bkgr");
("font-face-1 <... , font-face-n>", font-size, keyword-list) |
font-size specifies the size of the font. font-size can be a dimension or a number without units of measure. If you specify a dimension, you must specify a unit of measure. Without a unit of measure, the number becomes a size that is relative to all other font sizes in the document.
keyword-list specifies the weight, font style, and font width. You can include one value for each, in any order. The following table shows the keywords that you can use:
Keywords for Font Weight | Keywords for Font Style | Keywords for Font Width (table note 1) |
---|---|---|
MEDIUM | ITALIC | NORMAL* |
BOLD | ROMAN | COMPRESSED* |
DEMI_BOLD* | SLANT | EXTRA_COMPRESSED* |
EXTRA_BOLD* | NARROW* | |
LIGHT | WIDE* | |
DEMI_LIGHT* | EXPANDED* | |
EXTRA_LIGHT* |
TABLE NOTE 1: *Most fonts do not honor these
values.
Note: You can use
the value _UNDEF_ for
any style attribute. ODS treats an attribute that is set to _UNDEF_ as if
its value had never been set, even in the parent or beyond.
In the list of style attributes that follows, any attribute that is not documented as applying to a particular destination applies to all destinations that support the STYLE= option in the ODS statement that opens the destination. In Version 8 of the SAS System, the two destinations that support STYLE= are the HTML destination and the Printer destination.
Applies to: | cells |
Tip: | Generally, the background color of the cell overrides the background color of the table. You see the background color for the table only as the space between cells (see CELLSPACING= ). |
Applies to: | tables or cells |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables or cells |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables |
Tip: | Typically, when BORDERWIDTH=0, the ODS destination sets RULES=NONE (see the discussion of RULES= ) and FRAME=VOID (see the discussion of FRAME= ). |
Tip: | HTML automatically sets cell height appropriately. You should seldom need to specify this attribute. |
Applies to: | cells |
ODS Destinations: | HTML |
Applies to: | tables |
Applies to: | tables |
Interaction: | If BORDERWIDTH= is nonzero, and if the background color of the cells contrasts with the background color of the table, the color of the cell spacing is determined by the table's background. |
Applies to: | cells |
Tip: | The ODS destination automatically sets cell width appropriately. You should seldom need to specify this attribute. |
Applies to: | cells |
ODS Destinations: | HTML |
Applies to: | cells |
You cannot be sure what fonts are available to someone who is viewing your output in a browser or printing it on a high-resolution printer. Most devices support
Applies to: | cells |
Applies to: | cells |
Range: | 1 to 7, for size |
Restriction: | If you specify a dimension, you must specify a unit of measure. Without a unit of measure, the number becomes a relative size. |
Applies to: | cells |
MEDIUM | |
BOLD | |
DEMI_BOLD | |
EXTRA_BOLD | |
LIGHT | |
DEMI_LIGHT | |
EXTRA_LIGHT |
Applies to: | cells |
Restriction: | You cannot be sure what font weights are available to someone who is viewing your output in a browser or printing it on a high-resolution printer. Most devices support only MEDIUM and BOLD, and possibly LIGHT. |
NORMAL | |
COMPRESSED | |
EXTRA_COMPRESSED | |
NARROW | |
WIDE | |
EXPANDED |
Applies to: | cells |
Restriction: | Most fonts do not honor these values. |
Applies to: | tables or cells |
This value of frame-type | Creates this kind of frame around the table |
---|---|
ABOVE | a border at the top |
BELOW | a border at the bottom |
BOX | borders at the top, bottom, and both sides |
HSIDES | borders at the top and bottom |
LHS | a border at the left side |
RHS | a border at the right side |
VOID | no borders |
VSIDES | borders at the left and right sides |
Applies to: | tables |
Restriction: | Available only in Internet Explorer 5 or later. |
Default: | _SELF |
Applies to: | cells |
ODS Destinations: | HTML |
Applies to: | tables and cells |
ODS Destinations: | HTML |
Applies to: | tables and cells |
ODS Destinations: | HTML |
Applies to: | tables and cells |
ODS Destinations: | HTML |
Alias: | C |
Applies to: | tables and cells |
Alias: | L |
Applies to: | tables and cells |
Alias: | R |
Applies to: | tables and cells |
Restriction: | Not all contexts support RIGHT. If RIGHT is not supported, it is interpreted as CENTER. |
Applies to: | cells |
Applies to: | tables |
Tip: | Use OUTPUTWIDTH=100% to make the table as wide as the window that it is open in. |
ODS Destinations: | HTML |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables or cells |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables or cells |
ODS Destinations: | HTML |
Applies to: | tables or cells |
Applies to: | tables or cells |
ODS Destinations: | HTML |
This value of rule | Creates rules in these locations |
ALL | between all rows and columns |
COLS | between all columns |
GROUP | between the table header and the table and between the table and the table footer, if there is one |
NONE | no rules anywhere |
ROWS | between all rows |
Applies to: | tables |
Applies to: | cells |
ODS Destinations: | HTML |
Applies to: | cells |
ODS Destinations: | HTML |
Alias: | T |
Alias: | B |
Alias: | M |
Applies to: | cells |
RUN-Group Processing |
CATALOG | DATASETS | PLOT | PMENU | TRANTAB |
See the section on the individual procedure for more information.
Note: PROC SQL executes each query automatically. Neither the RUN nor
RUN CANCEL statement has any effect.
Creating Titles That Contain BY-Group Information |
Note: You must use the NOBYLINE option if you insert BY-group information into titles for the following base SAS procedures:
MEANS | STANDARD | SUMMARY. |
#BY-specification<.suffix> |
data groc; [1] input Region $9. Manager $ Department $ Sales; datalines; Southeast Hayes Paper 250 Southeast Hayes Produce 100 Southeast Hayes Canned 120 Southeast Hayes Meat 80 ...more lines of data... Northeast Fuller Paper 200 Northeast Fuller Produce 300 Northeast Fuller Canned 420 Northeast Fuller Meat 125 ;
proc sort data=groc; [2] by region department; run; options nobyline nodate pageno=1 linesize=64 pagesize=20; [3] proc chart data=groc; [4] by region department; vbar manager / type=sum sumvar=sales; title1 'This chart shows #byval2 sales'; title2 'in the #byval(region)..'; run; options byline; [5]
This partial output shows two BY groups with customized BY lines:
al
is appended to the label. In the second TITLE statement, #BYVAL1 inserts
the value of the first BY variable, Region, into the title.
options nobyline nodate pageno=1 linesize=64 pagesize=20; [1] proc chart data=groc; [2] by region; vbar manager / type=mean sumvar=sales; title1 '#byvar(region).al Analysis'; title2 'for the #byval1'; run; options byline; [3]
This partial output shows one BY group with a customized BY line:
options nobyline nodate pageno=1 linesize=64 pagesize=20; [1] proc chart data=groc; [2] by region department; vbar manager / type=sum sumvar=sales; title 'Information for #byline'; run; options byline; [3]
This partial output shows two BY groups with customized BY lines:
Shortcuts for Specifying Lists of Variable Names |
Notation | Meaning | |
---|---|---|
x1-xn |
specifies variables X1 through Xn. The numbers must be consecutive. | |
x: |
specifies all variables that begin with the letter X. | |
x--a |
specifies all variables between X and A, inclusive. This notation uses the position of the variables in the data set. | |
x-numeric-a |
specifies all numeric variables between X and A, inclusive. This notation uses the position of the variables in the data set. | |
x-character-a |
specifies all character variables between X and A, inclusive. This notation uses the position of the variables in the data set. | |
_numeric_ |
specifies all numeric variables. | |
_character_ |
specifies all character variables. | |
_all_ |
specifies all variables. |
Note: You cannot use shortcuts to list
variable names
in the INDEX CREATE statement in PROC DATASETS.
See SAS Language Reference: Concepts for complete documentation.
Formatted Values |
TA1
indicates that the employee is at the beginning level
for a ticket agent.
libname proclib 'SAS-data-library';
options nodate pageno=1 linesize=64 pagesize=40; proc print data=proclib.payroll(obs=10) noobs; title 'PROCLIB.PAYROLL'; title2 'First 10 Observations Only'; run;
This is a partial printing of PROCLIB.PAYROLL:
The following PROC FORMAT step creates the format $JOBFMT., which assigns descriptive names for each job:
proc format; value $jobfmt 'FA1'='Flight Attendant Trainee' 'FA2'='Junior Flight Attendant' 'FA3'='Senior Flight Attendant' 'ME1'='Mechanic Trainee' 'ME2'='Junior Mechanic' 'ME3'='Senior Mechanic' 'PT1'='Pilot Trainee' 'PT2'='Junior Pilot' 'PT3'='Senior Pilot' 'TA1'='Ticket Agent Trainee' 'TA2'='Junior Ticket Agent' 'TA3'='Senior Ticket Agent' 'NA1'='Junior Navigator' 'NA2'='Senior Navigator' 'BCK'='Baggage Checker' 'SCP'='Skycap'; run;
The FORMAT statement in this PROC MEANS step temporarily associates the $JOBFMT. format with the variable Jobcode:
options nodate pageno=1 linesize=64 pagesize=60; proc means data=proclib.payroll mean max; class jobcode; var salary; format jobcode $jobfmt.; title 'Summary Statistics for'; title2 'Each Job Code'; run;
PROC MEANS produces this output, which uses the $JOBFMT. format:
Note: Because formats are character strings, formats for numeric variables
are ignored when the values of the numeric variables are needed for mathematical
calculations.
proc format; value $codefmt 'FA1','FA2','FA3'='Flight Attendant' 'ME1','ME2','ME3'='Mechanic' 'PT1','PT2','PT3'='Pilot' 'TA1','TA2','TA3'='Ticket Agent' 'NA1','NA2'='Navigator' 'BCK'='Baggage Checker' 'SCP'='Skycap'; run; options nodate pageno=1 linesize=64 pagesize=40; proc means data=proclib.payroll mean max; class jobcode; var salary; format jobcode $codefmt.; title 'Summary Statistics for Job Codes'; title2 '(Using a Format that Groups the Job Codes)'; run;
PROC MEANS produces this output:
options nodate pageno=1 linesize=64 pagesize=40; proc print data=proclib.payroll(obs=10) noobs; format salary dollar8.; title 'Temporarily Associating a Format'; title2 'with the Variable Salary'; run;
PROC PRINT produces this output:
In this example, the FORMAT statement in the DATA step permanently associates the $YRFMT. variable with the variable Year. Thus, when you use the variable in a PROC step, the procedure uses the formatted values. The PROC MEANS step, however, contains a FORMAT statement that dissociates the $YRFMT. format from Year for this PROC MEANS step only. PROC MEANS uses the stored value for Year in the output.
proc format; value $yrfmt '1'='Freshman' '2'='Sophomore' '3'='Junior' '4'='Senior'; run; data debate; input Name $ Gender $ Year $ GPA @@; format year $yrfmt.; datalines; Capiccio m 1 3.598 Tucker m 1 3.901 Bagwell f 2 3.722 Berry m 2 3.198 Metcalf m 2 3.342 Gold f 3 3.609 Gray f 3 3.177 Syme f 3 3.883 Baglione f 4 4.000 Carr m 4 3.750 Hall m 4 3.574 Lewis m 4 3.421 ; options nodate pageno=1 linesize=64 pagesize=40; proc means data=debate mean maxdec=2; class year; format year; title 'Average GPA'; run;
PROC MEANS produces this output, which does not use the YRFMT. format:
Note: To ensure that SAS can find user-written formats, use the SAS
system option FMTSEARCH=. How to store formats is described in Storing Informats and Formats .
Processing All the Data Sets in a Library |
Printing All the Data Sets in a SAS Library shows how to print all the data sets in a library. You can use the same macro definition to perform any procedure on all the data sets in a library. Simply replace the PROC PRINT piece of the program with the appropriate procedure code.
Operating Environment-Specific Procedures |
Statistic Descriptions |
Statistic | Description | Procedures | |
---|---|---|---|
confidence intervals | FREQ, MEANS, UNIVARIATE | ||
CSS | corrected sum of squares | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
CV | coefficient of variation | MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
goodness-of-fit tests | FREQ, UNIVARIATE | ||
KURTOSIS | kurtosis | MEANS/SUMMARY, UNIVARIATE | |
MAX | largest (maximum) value | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
MEAN | mean | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
MEDIAN | median (50th percentile) | CORR (for nonparametric correlation measures), MEANS/SUMMARY, TABULATE, UNIVARIATE | |
MIN | smallest (minimum) value | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
MODE | most frequent value (if not unique, the smallest mode is used) | UNIVARIATE | |
N | number of observations on which calculations are based | CORR, FREQ, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
NMISS | number of missing values | FREQ, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
NOBS | number of observations | MEANS/SUMMARY, UNIVARIATE | |
PCTN | the percentage of a cell or row frequency to a total frequency | REPORT, TABULATE | |
PCTSUM | the percentage of a cell or row sum to a total sum | REPORT, TABULATE | |
Pearson correlation | CORR | ||
percentiles | FREQ, MEANS/SUMMARY, TABULATE, UNIVARIATE | ||
RANGE | range | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
robust statistics | trimmed means, Winsorized means | UNIVARIATE | |
SKEWNESS | skewness | MEANS/SUMMARY, UNIVARIATE | |
Spearman correlation | CORR | ||
STD | standard deviation | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
STDERR | the standard error of the mean | MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
SUM | sum | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
SUMWGT | sum of weights | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
tests of location | UNIVARIATE | ||
USS | uncorrected sum of squares | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE | |
VAR | variance | CORR, MEANS/SUMMARY, REPORT, SQL, TABULATE, UNIVARIATE |
Computational Requirements for Statistics |
Statistics are reported as missing if they cannot be computed.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.