0% found this document useful (0 votes)
19 views

2 File Reference and Option Setting

File Reference and Option Setting for SAS base programming exam

Uploaded by

Kent
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

2 File Reference and Option Setting

File Reference and Option Setting for SAS base programming exam

Uploaded by

Kent
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

2 File Reference and Option Setting

1. Defining Libraries

 To define libraries, you can use a LIBNAME statement:

LIBNAME libref 'SAS-data-library';

where
 libref is 1 to 8 characters long, begins with a letter or underscore, and
contains only letters, numbers, or underscores.
 'SAS-data-library is the name of a SAS data library in which SAS
data files are stored. The specification of the physical name of the library
differs by operating environment.

 The LIBNAME statement is global. The effect remains until you modify them, cancel
them, or end your SAS session.
 The LIBNAME statement assigns the libref for the current SAS session only. The
contents of the library, however, still exist on your operating system.
 Files that were created with other software products can also be referenced by using
the appropriate engine for that file type.

LIBNAME libref engine 'SAS-data-library';

where
 engine is the name of a library engine that is supported in your operating
environment. Examples are BMDP, OSIRIS, and SPSS files.

Example 1

Suppose that the operating system is Windows. What does the following program do?

libname clinic spss 'e:\sas2013';

Create a library reference with which SPSS files can be directly accessed.

Example 2

Suppose that the operating system is UNIX. What does the following program do?

libname clinic '/users/summer/sas2014';

1
Create a library reference with which SAS files can be directly accessed.

Example 3

Suppose that the operating system is Windows. What is wrong of the following program?

libname clinic123 spss '/users/summer/sas2014';

The name of the library reference is too long

2. Viewing Libraries and Data Sets

 CONTENTS procedure creates SAS output that describes:


o the contents of a library
o the descriptor information for an individual SAS data set.

PROC CONTENTS DATA=SAS-file-specification <options>;


RUN;

where
 SAS-file-specification specifies an entire library or a specific
SAS data set within a library. SAS-file-specification takes one of
the following forms:
o <libref.>SAS-data-set names one SAS data set to process.
o <libref.>_ALL_ requests a listing of all files in the library.
 NODS is an option that suppresses the printing of detailed information about
each file when you specify _ALL_ . (You can specify NODS only when you
specify _ALL_ .)

 DATASETS procedure shows the contents of a SAS library or a SAS data set, and
performs management (e.g. copying, deleting, and modifying) of data sets.

PROC DATASETS;
CONTENTS DATA=SAS-file-specification <options>;
QUIT;

2
 Generally, PROC CONTENTS and PROC DATASETS are the same in terms of
functionality. The options for the PROC CONTENTS statement and the CONTENTS
statement in the DATASETS procedure are the same.
 PROC CONTENTS and PROC DATASETS list variables alphabetically by default.
To list variable names in the order of their logical position (or creation order) in the
data set, specify the VARNUM option in PROC CONTENTS or in the CONTENTS
statement in PROC DATASETS.
 PROC PRINT displays the contents of a data set:

PROC PRINT DATA=SAS-file-specification;


RUN;

 PROC FREQ displays the table which contains the frequencies of value of each
variables of a data set:

PROC PRINT FREQ=SAS-file-specification;


RUN;

Example 4

Write a SAS program that prints the descriptor portion of files in the library Sasuser with
all variables shown in alphabetically order.

proc contents data=sasuser._all_;


proc datasets;
contents data=sasuser._all_;
run;
RUN;

Example 5

What will be shown in the Output windows after each of the following program is executed?
(a) proc contents data=summer._all_ nods;
run;

(b) proc contents data=summer._all_ varnum;


run;

3
(c) proc datasets;
contents data=sasuser._all_ varnum;
run;

(d) proc print data=summer.airports;


run;

(e) proc freq data=summer.airports;


run;

(a) The contents of the library ‘summer’. The detail


information of each file is suppressed.

(b) The contents of the library ‘summer’. The detail


information of each file is shown with the variable
listed in logical order.

(c) Same as (b)

(d) The data set ‘summer.airports’ is shown.

(e) The frequency summary of each variable in


‘summer.airports’.

3. Specifying Output Formats

 There are two formats for output: LISTING and HTML. To specify LISTING as the
output, use ODS LISTING statement; to specify HTML as the format, use ODS
HTML statement. To turn off HTML or LISTING format, use ODS HTML CLOSE or
ODS LISTING CLOSE respectively.
 OPTIONS statement changes the settings from that point onward:

OPTIONS options;

where options specifies one or more system options to be changed:


 DATE /NODATE suppress/enable the display of the date
 NUMBER /NONUMBER suppress/enable the display of the page number
 PAGENO= specify the beginning page number
 PAGESIZE= option (alias PS=) specifies how many lines each page of
output
 LINESIZE= option (alias LS=) specifies the width of the print line for
your procedure output and log.
 YEARCUTOFF= option specifies which 100-year span is used to interpret
two-digit year values. The default value of YEARCUTOFF= is 1920.
 FIRSTOBS= specifies the number of the first observation to process.
 OBS= specifies the number of the last observation to process. The default
value for OBS= is MAX, which is the largest signed integer.

4
 FIRSTOBS= and OBS= can be data set options. The data set options override the
system options in the procedure only. For example,

PROC PRINT DATA=filename (firstobs=n1 obs= n2);


RUN;

Example 6

What will be shown in the Output windows after the following SAS program is executed?
options nodate firstobs=5;
proc print data=summer.airports;
run;

options nonumber obs=5;


proc print data=summer.airports;
run;

The first PROC PRINT shows the whole dataset starting from
observation 5. The date is suppressed.

The second PROC PRINT shows observation 5 only. The page


number and the date are both suppressed.

Example 7

Suppose that YEARCUTOFF=1920. How are the following dates interpreted? What if
YEARCUTOFF=1950?

12/7/1941 18-Dec-15 4/15/1930 15-Apr-95

1941
2015
1930
1995

5
Example 8

What is wrong of the following program?

PROC PRINT DATA=summer.admit (firstobs=1, obs=MAX);


RUN;

(firstobs=1, obs=MAX) should not contain a comma.

Example 9

Write a SAS program for each of the following information.

(i) Number of observations in summer.heart.


(ii) Content of 10 observations of summer.insure starting from the 10th observation.

proc contents data=summer.heart nods;


run;

proc datasets;
contents data=summer.heart;
run;

proc print data=summer.insure (firstobs=10 obs=19);


run;

4. Answers of Examples

1. Create a library reference with which SPSS files can be


directly accessed.

2. Create a library reference with which SAS files can be


directly accessed.

3. The name of the library reference is too long

4. proc contents data=sasuser._all_; proc datasets; contents


data=sasuser._all_; run;

5.

6
(a) The contents of the library ‘summer’. The detail
information of each file is suppressed.

(b) The contents of the library ‘summer’. The detail


information of each file is shown with the variable
listed in logical order.
(c) Same as (b)
(d) The data set ‘summer.airports’ is shown.
(e) The frequency summary of each variable in
‘summer.airports’.

6. The first PROC PRINT shows the whole dataset starting from
observation 5. The date is suppressed. The second PROC PRINT
shows observation 5 only. The page number and the date are
both suppressed.

7. 1941 2015 1930 1995

8. (firstobs=1, obs=MAX) should not contain a comma.

9. proc contents data=summer.heart nods; run;

proc datasets; contents data=summer.heart; run;

proc print data=summer.insure (firstobs=10 obs=19); run;

You might also like