![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS Procedures Guide |
This section contains background information on concepts and tools that are common to many base SAS procedures.
| Input Data Sets |
Many base procedures require an input SAS data set. You specify the input SAS data set using the DATA= option in the procedure statement, for example,
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 |
Prior to Version 7, SAS procedures that produced printed output (that is, output that was destined for the procedure output file) generated output that was designed for a traditional line-printer. This type of output has limitations that prevent users from getting the most value from their results:
Beginning with Version 7, procedure output is 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.
When you run a procedure that supports ODS, SAS automatically stores a link to the ODS output in the Results folder in the Results window.
Consider the following SAS program, which generates Listing 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;
proc univariate data=statepop mu0=3.5; var citypop_90 noncitypop_90; title; run;
Some of the Listing output appears in Partial Listing Output Produced by PROC UNIVARIATE. The Results folder (see View of the Results Folder) shows the folders and output objects that the procedure produces.
Partial Listing Output Produced by PROC UNIVARIATE
1
The UNIVARIATE Procedure
Variable: CityPop_90 (1990 metropolitan pop in millions)
Moments
N 51 Sum Weights 51
Mean 3.87701961 Sum Observations 197.728
Std Deviation 5.16465302 Variance 26.6736408
Skewness 2.87109259 Kurtosis 10.537867
Uncorrected SS 2100.27737 Corrected SS 1333.68204
Coeff Variation 133.21194 Std Error Mean 0.72319608
Basic Statistical Measures
Location Variability
Mean 3.877020 Std Deviation 5.16465
Median 2.423000 Variance 26.67364
Mode . Range 28.66500
Interquartile Range 3.60000
Tests for Location: Mu0=3.5
Test -Statistic- -----p Value------
Student's t t 0.521324 Pr > |t| 0.6044
Sign M -9.5 Pr >= |M| 0.0110
Signed Rank S -147 Pr >= |S| 0.1706 |
2
The UNIVARIATE Procedure
Variable: CityPop_90 (1990 metropolitan pop in millions)
Quantiles (Definition 5)
Quantile Estimate
100% Max 28.799
99% 28.799
95% 14.166
90% 9.574
75% Q3 4.376
50% Median 2.423
25% Q1 0.776
10% 0.257
5% 0.191
1% 0.134
0% Min 0.134
Extreme Observations
-----Lowest---- -----Highest----
Value Obs Value Obs
0.134 41 10.083 9
0.152 3 12.023 18
0.191 39 14.166 26
0.221 36 16.515 7
0.226 50 28.799 49 |
| |
|
In addition to creating Listing output, the Output Delivery System can create HTML output by formatting output objects in Hyper text Markup Language (HTML). You can browse these files with Internet Explorer, Netscape, or any other browser that fully supports the HTML 3.2 tag set.
The ODS HTML statement, which generates the HTML files, can create
For example, the ODS 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.
Note: This example is for the UNIX operating environment. To successfully run the example in another operating environment, you may need to change the file specifications. See
Alternate ODS HTML Statements for Running Examples in Different Operating Environments.
/* Create HTML files. */
ods html file='body.htm'
contents='contents.htm'
page='page.htm'
frame='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. |
|
For more information about creating HTML output, see the discussion of the ODS HTML Statement in Chapter 3, "The ODS Statements" in The Complete Guide to the SAS Output Delivery System. You can see many examples of HTML output in SAS Procedures Guide online documentation.
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.
Several of the features of the Output Delivery System (such as selecting and excluding output objects to send to ODS destinations or creating a data set from an output object) require that you specify one or more particular output objects for the system to process. You identify an output object by its name, its label, or its path. To learn what these are, run your SAS program preceded by this statement:
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 Chapter 3, "The ODS Statements" in The Complete Guide to the SAS Output Delivery System.
Some procedures, such as PROC UNIVARIATE, produce multiple output objects. Any procedure that uses ODS produces multiple output objects when you use BY-group processing. ODS enables you to select which of these output objects go to the open ODS destinations. (ODS destinations include the Listing destination, the HTML destination, and the Output destination. For more information about ODS destinations, see Chapter 1, "Basic Concepts about the Output Delivery System" 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.
Note: This example is for the UNIX operating environment. To successfully run the example in another operating environment, you may need to change the file specifications. See
Alternate ODS HTML Statements for Running Examples in Different Operating Environments.
/* Create HTML files. */
ods html body='select-body.htm'
contents='select-contents.htm'
page='select-pages.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. |
|
For more information about selecting output objects, see the documentation
for the ODS SELECT statement in Chapter 3, "The ODS Statements"
in The Complete Guide to the SAS Output Delivery System.
The Output Delivery System also enables you to create a data set from an output object.
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.
Note: This example is for the UNIX operating environment. To successfully run the example in another operating environment, you may need to change the file specifications. See
Alternate ODS HTML Statements for Running Examples in Different Operating Environments.
/* 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 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. |
|
For more information about creating output data sets, see the discussion
of the ODS OUTPUT statement in Chapter 3, "The ODS Statements,"
in The Complete Guide to the SAS Output Delivery System.
Many procedures that fully support ODS provide table definitions that enable you to customize each output object that the procedure produces. You do so by creating an alternate table definition for the procedure to use.
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
Note: This example is for the UNIX operating environment. To successfully run the example in another operating environment, you may need to change the file specifications. See
Alternate ODS HTML Statements for Running Examples in Different Operating Environments.
/* These options affect only the Listing output. */ options nodate pageno=1 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;
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;
end;
define VarValue;
print_headers = off;
format = 7.3;
style=data{font_style=italic font_weight=bold};
end;
/* This DEFINE block defines a footer that */
/* appears at the bottom of the table of */
/* measures. */
define footer f;
text "Measures computed on &SysDate";
style = FooterEmphasis;
end;
end;
/* End the PROC TEMPLATE step. */
end;
/* 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 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;
Customized Output from PROC UNIVARIATE
| A Gallery of HTML Files Produced by Base Procedures |
This section illustrates the HTML output that you can get from routing selected examples from the documentation on individual procedures through the HTML destination. Each piece of output shown was created by running the specified example with this ODS HTML statement preceding it:
ods html body='external-file';
You must execute the following statement before you can view the
resulting HTML files in a browser:
ods html close;
The SAS program that produces this output is in Summarizing Information with the Universal Class Variable ALL.
The SAS program that produces this output is in Analyzing a 2×2 Contingency Table.
The SAS program that produces this output is in Summing Numeric Variables with One BY Group.
The SAS program that produces this output is in Specifying Style Elements for HTML Output in the PROC REPORT Statement.
| Customizing the Styles Used in HTML Output |
A style determines the overall look of the document that uses it. Each style is a collection of style elements, each of which affects a particular part of the document. Procedures may use different style elements in different parts of their output. For example, a procedure can use one style element for column headers and another for data. Each style element is, in turn, a collection of attributes and values. The attributes determine the size, face, and weight of the type that is used, the color of the foreground and background, and other such features.
For a list of the attributes, see What Style Attributes Can Base Procedures Specify?.
SAS Institute ships a number of styles with the SAS System. To see a list of these styles,
The Output Delivery System 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
inThe Complete Guide to the SAS Output Delivery System).
To see the elements of a style, submit this PROC TEMPLATE step:
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).
In most cases, if you want to alter the style of an HTML 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.)
A procedure uses one or more templates to produce output objects. Each template can specify the use of one or more style elements for various parts of the output.
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
output directly from the PROC step that creates the report. Information on
how to do this is provided with the syntax for these procedures.
The following list describes the style attributes that you can specify from the TABULATE and REPORT procedures. Procedures that support the Output Delivery System create HTML files and put their output in HTML tables in these files. Some of the style attributes apply to the HTML table as a whole; others apply to individual cells in the HTML table. The procedure documentation tells you which style attributes you can set from which statements in the procedure.
Note: The default value that is used for an attribute depends on the
style that is in use. For information on viewing the attributes in a style,
see What Styles Are Shipped with the Software?.
The implementation of an attribute depends of the browser that you use.
Many values for style attributes are one of the following:
| 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. ![[cautend]](../common/images/cautend.gif)
| 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. |
| Applies to: | cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Tip: | Typically, when BORDERWIDTH=0, the browser 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 |
| Applies to: | HTML tables |
| Applies to: | HTML tables |
| Interaction: | If BORDERWIDTH= is nonzero, and if the background color of the cells contrasts with the background color of the table, the cell spacing appears as a rule that is the same color as the table's background. |
| Applies to: | cells |
| Tip: | HTML automatically sets cell width appropriately. You should seldom need to specify this attribute. |
| Applies to: | cells |
You cannot be sure what fonts are available to someone who is viewing your HTML output in a browser. Most devices support
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Range: | 1 to 7 |
| Applies to: | HTML tables or cells |
| MEDIUM | |
| BOLD | |
| DEMI_BOLD | |
| EXTRA_BOLD | |
| LIGHT | |
| DEMI_LIGHT | |
| EXTRA_LIGHT | |
| BLACK |
| Applies to: | HTML tables or cells |
| Restriction: | You cannot be sure what font weights are available to someone who is viewing your HTML output in a browser. Most devices support only MEDIUM and BOLD, and possibly LIGHT. |
| NORMAL | |
| COMPRESSED | |
| EXTRA_COMPRESSED | |
| NARROW | |
| WIDE | |
| EXPANDED |
| Applies to: | HTML tables or cells |
| Restriction: | Most fonts do not honor these values. |
| Applies to: | HTML 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: | HTML tables |
| Applies to: | HTML tables and cells |
| Applies to: | HTML tables and cells |
| Applies to: | HTML tables and cells |
| Alias: | C |
| Applies to: | HTML tables |
| Alias: | L |
| Applies to: | cells |
| Alias: | R |
| Applies to: | cells |
| Restriction: | Not all contexts support RIGHT. If RIGHT is not supported, it is interpreted as CENTER. |
| Applies to: | cells |
| Applies to: | HTML tables |
| Tip: | Use OUTPUTWIDTH=100% to make the HTML table as wide as the window that it is open in. |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| Applies to: | HTML tables or cells |
| 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: | HTML tables |
| Alias: | T |
| Alias: | B |
| Alias: | M |
| Applies to: | cells |
| RUN-Group Processing |
RUN-group processing enables you to submit a PROC step with a RUN statement without ending the procedure. You can continue to use the procedure without issuing another PROC statement. To end the procedure, use a RUN CANCEL or a QUIT statement. Several base SAS procedures support 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 |
BY-group processing uses a BY statement to process observations
that are ordered, grouped, or indexed according to the values of one or more
variables. By default, when you use BY-group processing in a procedure step,
a BY line identifies each group. This section explains how to create titles
that serve as customized BY lines.
When you insert BY-group processing information into a title, you usually want to eliminate the default BY line. To suppress it, use the SAS system option NOBYLINE.
Note: You must use the NOBYLINE option if you insert BY-group information into titles for the following base SAS procedures:
| MEANS | STANDARD | SUMMARY. |
The general form for inserting BY-group information into a title is
| #BY-specification<.suffix> |
This example
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:
This example inserts the name of a BY variable and the value of a BY variable into the title. The program
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:
This example inserts the complete BY line into the title. The program
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:
The SAS System does not issue error or warning messages for incorrect #BYVAL, #BYVAR, or #BYLINE specifications. Instead, the text of the item simply becomes part of the title.
| Shortcuts for Specifying Lists of Variable Names |
Several statements in procedures allow multiple variable names. You can use these shortcut notations instead of specifying each variable name:
| 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 |
Typically,
when you print or group variable values, base SAS procedures use the formatted
values. This section contains examples of how base procedures use formatted
values.
The following example prints
the formatted values of the data set PROCLIB.PAYROLL. (A DATA step creates this
data set.) In PROCLIB.PAYROLL, the variable Jobcode indicates the job and
level of the employee. For example, 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:
If you want to associate a format with a variable temporarily, you can use the FORMAT statement. For example, the following PROC PRINT step associates the DOLLAR8. format with the variable Salary for the duration of this PROC PRINT step only:
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:
If a variable has a permanent format that you do not want a procedure to use, temporarily dissociate the format from the variable using a FORMAT statement.
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:
When a procedure processes a data set, it checks to see if a
format is assigned to the BY variable. If so, the procedure adds observations
to the current BY groups until the formatted value changes. If nonconsecutive internal values of the BY variable(s) have the same formatted value,
the values are grouped into different BY groups. This results in two BY groups
with the same formatted value. Further, if different and consecutive internal values of the BY variable(s) have the same formatted value,
they are included in the same BY group.
If SAS cannot find a format, it stops processing and prints an error message in the SAS log. You can suppress this behavior with the SAS system option NOFMTERR. When you use NOFMTERR, and SAS cannot find the format, SAS uses a default format and continues to process. Typically, for the default, SAS uses the BESTw. format for numeric variables and the $w. format for character variables.
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 |
You can use the SAS Macro Facility to run the same procedure on every data set in a library. The macro facility is part of base SAS software.
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 |
Several base SAS procedures are specific to one operating environment or one release. Operating Environment-Specific Procedurescontains a table with additional information. These procedures are described in more detail in the SAS documentation for operating environments.
| Statistic Descriptions |
Common Descriptive Statistics That Base Procedures Calculate identifies common descriptive statistics that are available in several base procedures. See Keywords and Formulas for more detailed information about available statistics and theoretical information.
| 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 |
The following requirements are computational requirements for the statistics that are listed in Common Descriptive Statistics That Base Procedures Calculate. They do not describe recommended sample sizes.
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.