Previous Page | Next Page

Functions and CALL Routines

GETOPTION Function



Returns the value of a SAS system or graphics option.
Category: Special

Syntax
Arguments
Examples
Example 1: Using GETOPTION to Save and Restore the YEARCUTOFF Option
Example 2: Using GETOPTION to Obtain Different Reporting Options

Syntax

GETOPTION(option-name<,reporting-options<,...>>)

Arguments

option-name

is a character constant, variable, or expression that specifies the name of the system option.

Tip: Do not put an equal sign after the name. For example, write PAGESIZE= as PAGESIZE.
Tip: SAS options that are passwords, such as EMAILPW and METAPASS, return the value xxxxxxxx , and not the actual password.
reporting-options

is a character constant, variable, or expression that specifies the reporting options. You can separate the options with blanks, or you can specify each reporting option as a separate argument to the GETOPTION function. The following is a list of reporting options:

IN

reports graphic units of measure in inches.

CM

reports graphic units of measure in centimeters.

EXPAND | KEYEXPAND

for options that contain environment variables or keywords, returns the value of the environment variable or keyword in the option value.

HOWSET

returns a character string that specifies how an option value was set.

Restriction: HOWSET is valid only for SAS system options. SAS issues an error message when the HOWSET option is specified and option-name is a graphics option.
HOWSCOPE

returns a character string that specifies the scope of an option.

Restriction: HOWSCOPE is valid only for SAS system options. SAS issues an error message when the HOWSCOPE option is specified and option-name is a graphics option.
KEYWORD

returns option values in a KEYWORD= format that would be suitable for direct use in the SAS OPTIONS or GOPTIONS global statements.

Note:   For a system option with a null value, the GETOPTION function returns a value of ' ' (single quotation marks with a blank space between them), for example EMAILID=' '.  [cautionend]


Examples


Example 1: Using GETOPTION to Save and Restore the YEARCUTOFF Option

This example saves the initial value of the YEARCUTOFF option and then resets the value to 1920. The DATA step that follows verifies the option setting and performs date processing. When the DATA step ends, the YEARCUTOFF option is set to its original value.

%let cutoff=%sysfunc(getoption
                    (yearcutoff,keyword));
options yearcutoff=1920;
data ages;
  if getoption('yearcutoff') = '1920' then
     do;
        ...more statements...
     end;
  else put 'Set Option YEARCUTOFF to 1920';
run;

options &cutoff;


Example 2: Using GETOPTION to Obtain Different Reporting Options

This example defines a macro to illustrate the use of the GETOPTION function to obtain the value of system and graphics options by using different reporting options.

%macro showopts;
  %put MAPS= %sysfunc(
     getoption(MAPS));  
  %put MAPSEXPANDED= %sysfunc(
     getoption(MAPS, EXPAND));
  %put PAGESIZE= %sysfunc(
     getoption(PAGESIZE));
  %put PAGESIZESETBY= %sysfunc(
     getoption(PAGESIZE, HOWSET));
  %put PAGESIZESCOPE= %sysfunc(
     getoption(PAGESIZE, HOWSCOPE));
  %put PS= %sysfunc(
     getoption(PS));
  %put LS= %sysfunc(
     getoption(LS));
  %put PS(keyword form)= %sysfunc(
     getoption(PS,keyword));
  %put LS(keyword form)= %sysfunc(
     getoption(LS,keyword));
  %put FORMCHAR= %sysfunc(
     getoption(FORMCHAR));
  %put HSIZE= %sysfunc(
     getoption(HSIZE));
  %put VSIZE= %sysfunc(
     getoption(VSIZE));
  %put HSIZE(in/keyword form)= %sysfunc(
     getoption(HSIZE,in,keyword));
  %put HSIZE(cm/keyword form)= %sysfunc(
     getoption(HSIZE,cm,keyword));
  %put VSIZE(in/keyword form)= %sysfunc(
     getoption(VSIZE,in,keyword));
  %put HSIZE(cm/keyword form)= %sysfunc(
     getoption(VSIZE,cm,keyword));
%mend;
goptions VSIZE=8.5 in HSIZE=11 in;
options PAGESIZE=67;

%showopts

The following is SAS output from the example.

MAPS= !SASROOT\MAPS
MAPSEXPANDED= ( 'C:\PROGRAM FILES\SAS\SAS 9.1\MAPS' )
PAGESIZE= 67
PAGESIZESETBY= OPTIONS STATEMENT
PAGESIZESCOPE= DMS PROCESS
PS= 23
LS= 76
PS(keyword form)= PS=23
LS(keyword form)= LS=76
FORMCHAR= |----|+|---+=|-/\<>*
HSIZE= 11.0000 in.
VSIZE= 8.5000 in.
HSIZE(in/keyword form)= HSIZE=11.0000 in.
HSIZE(cm/keyword form)= HSIZE=27.9400 cm.
VSIZE(in/keyword form)= VSIZE=8.5000 in.
HSIZE(cm/keyword form)= VSIZE=21.5900 cm.

Note:   The default settings for the PAGESIZE= and the LINESIZE= options depend on the mode you use to run SAS.   [cautionend]

Previous Page | Next Page | Top of Page