Examples: DATASETS Procedure


Example 1: Manipulating SAS Files

Procedure features:

  • PROC DATASETS statement options:

    • DETAILS

    • LIBRARY=

  • CHANGE statement

  • COPY statement options:

    • MEMTYPE

    • MOVE

    • OUT=

  • DELETE statement option:

    • MEMTYPE=

  • EXCHANGE statement

  • EXCLUDE statement

  • SELECT statement option:

    • MEMTYPE=

This example

  • changes the names of SAS files

  • copies SAS files between SAS data libraries

  • deletes SAS files

  • selects SAS files to copy

  • exchanges the names of SAS files

  • excludes SAS files from a copy operation.

Program

Write the programming statements to the SAS log. The SOURCE system option accomplishes this.

 options pagesize=60 linesize=80 nodate pageno=1 source;  libname dest1 '  SAS-data-library-1  ';  libname dest2 '  SAS-data-library-2  ';  libname health '  SAS-data-library-3  '; 

Specify the procedure input library, and add more details to the directory. DETAILS prints these additional columns in the directory: Obs, Entries or Indexes , Vars , and Label . All member types are available for processing because the MEMTYPE= option does not appear in the PROC DATASETS statement.

 proc datasets library=health details; 

Delete two files in the library, and modify the names of a SAS data set and a catalog. The DELETE statement deletes the TENSION data set and the A2 catalog. MT=CATALOG applies only to A2 and is necessary because the default member type for the DELETE statement is DATA. The CHANGE statement changes the name of the A1 catalog to POSTDRUG. The EXCHANGE statement exchanges the names of the WEIGHT and BODYFAT data sets. MEMTYPE= is not necessary in the CHANGE or EXCHANGE statement because the default is MEMTYPE=ALL for each statement.

 delete tension a2(mt=catalog);  change a1=postdrug;  exchange weight=bodyfat; 

Restrict processing to one member type and delete and move data views. MEMTYPE=VIEW restricts processing to SAS data views. MOVE specifies that all SAS data views named in the SELECT statements in this step be deleted from the HEALTH data library and moved to the DEST1 data library.

 copy out=dest1 move memtype=view; 

Move the SAS data view SPDATA from the HEALTH data library to the DEST1 data library.

 select spdata; 

Move the catalogs to another data library. The SELECT statement specifies that the catalogs ETEST1 through ETEST5 be moved from the HEALTH data library to the DEST1 data library. MEMTYPE=CATALOG overrides the MEMTYPE=VIEW option in the COPY statement.

 select etest1-etest5 / memtype=catalog; 

Exclude all files with a specified criteria from processing. The EXCLUDE statement excludes from the COPY operation all SAS files that begin with the letter D and the other SAS files listed. All remaining SAS files in the HEALTH data library are copied to the DEST2 data library.

 copy out=dest2;        exclude d: mlscl oxygen test2 vision weight;  quit; 

SAS Log

 1    options pagesize=60 linesize=80 nodate pageno=1 source;  2    libname dest1 'c:\Myfiles\dest1';  NOTE: Libref DEST1 was successfully assigned as follows:        Engine:        V9        Physical Name: c:\Myfiles\dest1  3    libname dest2 'c:\Myfiles\dest2';  NOTE: Libref DEST2 was successfully assigned as follows:        Engine:        V9        Physical Name: c:\Myfiles\dest2  4    libname health 'c:\Myfiles\health';  NOTE: Libref HEALTH was successfully assigned as follows:        Engine:        V9        Physical Name: c:\Myfiles\health  5    proc datasets library=health details;                                     Directory                Libref         HEALTH                Engine         V9                Physical Name  c:\Myfiles\health                File Name      c:\Myfiles\health                Member   Obs, Entries                   File    # Name      Type      or Indexes   Vars  Label      Size  Last Modified    1 A1        CATALOG       23                       62464   19FEB2002:14:41:15    2 A2        CATALOG        1                       17408   19FEB2002:14:41:15    3 ALL       DATA          23        17             13312   19FEB2002:14:41:19    4 BODYFAT   DATA           1         2              5120   19FEB2002:14:41:19    5 CONFOUND  DATA           8         4              5120   19FEB2002:14:41:19    6 CORONARY  DATA          39         4              5120   19FEB2002:14:41:20    7 DRUG1     DATA           6         2   JAN95      5120   19FEB2002:14:41:20                                             Data    8 DRUG2     DATA          13         2   MAY95      5120   19FEB2002:14:41:20                                             Data    9 DRUG3     DATA          11         2   JUL95      5120   19FEB2002:14:41:20                                             Data  10  DRUG4     DATA           7         2   JAN92      5120   19FEB2002:14:41:20                                             Data  11  DRUG5     DATA           1         2   JUL92      5120   19FEB2002:14:41:20                                             Data  12  ETEST1    CATALOG        1                       17408   19FEB2002:14:41:20  13  ETEST2    CATALOG        1                       17408   19FEB2002:14:41:20  14  ETEST3    CATALOG        1                       17408   19FEB2002:14:41:20  15  ETEST4    CATALOG        1                       17408   19FEB2002:14:41:20  16  ETEST5    CATALOG        1                       17408   19FEB2002:14:41:20  17  ETESTS    CATALOG        1                       17408   19FEB2002:14:41:21  18  FORMATS   CATALOG        6                       17408   19FEB2002:14:41:21  19  GROUP     DATA         148        11             25600   19FEB2002:14:41:21  20  INFANT    DATA         149         6             17408   05FEB2002:12:52:30  21  MLSCL     DATA          32         4   Multiple   5120   19FEB2002:14:41:21                                             Sclerosi                                             s Data  22  NAMES     DATA           7         4              5120   19FEB2002:14:41:21  23  OXYGEN    DATA          31         7              9216   19FEB2002:14:41:21  24  PERSONL   DATA         148        11             25600   19FEB2002:14:41:21  25  PHARM     DATA           6         3   Sugar      5120   19FEB2002:14:41:21                                             Study  26  POINTS    DATA           6         6              5120   19FEB2002:14:41:21  27  PRENAT    DATA         149         6             17408   19FEB2002:14:41:22  28  RESULTS   DATA          10         5              5120   19FEB2002:14:41:22  29  SLEEP     DATA         108         6              9216   19FEB2002:14:41:22  30  SPDATA    VIEW           .         2              5120   19FEB2002:14:41:29  31  SYNDROME  DATA          46         8              9216   19FEB2002:14:41:22  32  TENSION   DATA           4         3              5120   19FEB2002:14:41:22  33  TEST2     DATA          15         5              5120   19FEB2002:14:41:22  34  TRAIN     DATA           7         2              5120   19FEB2002:14:41:22  35  VISION    DATA          16         3              5120   19FEB2002:14:41:22  36  WEIGHT    DATA          83        13   Californ   13312  19FEB2002:14:41:22                                             ia                                             Results  37  WGHT      DATA          83        13   Californ    13312   19FEB2002:14:41:23                                             ia                                             Results  6       delete tension a2(mt=catalog);  7       change a1=postdrug;  8       exchange weight=bodyfat;  NOTE: Deleting HEALTH.TENSION (memtype=DATA).  NOTE: Deleting HEALTH.A2 (memtype=CATALOG).  NOTE: Changing the name HEALTH.A1 to HEALTH.POSTDRUG (memtype=CATALOG).  NOTE: Exchanging the names HEALTH.WEIGHT and HEALTH.BODYFAT (memtype=DATA).  9       copy out=dest1 move memtype=view;  10         select spdata;  11         select etest1-etest5 / memtype=catalog;  NOTE: Moving HEALTH.SPDATA to DEST1.SPDATA (memtype=VIEW).  NOTE: Moving HEALTH.ETEST1 to DEST1.ETEST1 (memtype=CATALOG).  NOTE: Moving HEALTH.ETEST2 to DEST1.ETEST2 (memtype=CATALOG).  NOTE: Moving HEALTH.ETEST3 to DEST1.ETEST3 (memtype=CATALOG).  NOTE: Moving HEALTH.ETEST4 to DEST1.ETEST4 (memtype=CATALOG).  NOTE: Moving HEALTH.ETEST5 to DEST1.ETEST5 (memtype=CATALOG).  12      copy out=dest2;  13         exclude d: mlscl oxygen test2 vision weight;  14   quit;  NOTE: Copying HEALTH.ALL to DEST2.ALL (memtype=DATA).  NOTE: There were 23 observations read from the data set HEALTH.ALL.  NOTE: The data set DEST2.ALL has 23 observations and 17 variables.  NOTE: Copying HEALTH.BODYFAT to DEST2.BODYFAT (memtype=DATA).  NOTE: There were 83 observations read from the data set HEALTH.BODYFAT.  NOTE: The data set DEST2.BODYFAT has 83 observations and 13 variables.  NOTE: Copying HEALTH.CONFOUND to DEST2.CONFOUND (memtype=DATA).  NOTE: There were 8 observations read from the data set HEALTH.CONFOUND.  NOTE: The data set DEST2.CONFOUND has 8 observations and 4 variables.  NOTE: Copying HEALTH.CORONARY to DEST2.CORONARY (memtype=DATA).  NOTE: There were 39 observations read from the data set HEALTH.CORONARY.  NOTE: The data set DEST2.CORONARY has 39 observations and 4 variables.  NOTE: Copying HEALTH.ETESTS to DEST2.ETESTS (memtype=CATALOG).  NOTE: Copying HEALTH.FORMATS to DEST2.FORMATS (memtype=CATALOG).  NOTE: Copying HEALTH.GROUP to DEST2.GROUP (memtype=DATA).  NOTE: There were 148 observations read from the data set HEALTH.GROUP.  NOTE: The data set DEST2.GROUP has 148 observations and 11 variables.  NOTE: Copying HEALTH.INFANT to DEST2.INFANT (memtype=DATA).  NOTE: There were 149 observations read from the data set HEALTH.INFANT.  NOTE: The data set DEST2.INFANT has 149 observations and 6 variables.  NOTE: Copying HEALTH.NAMES to DEST2.NAMES (memtype=DATA).  NOTE: There were 7 observations read from the data set HEALTH.NAMES.  NOTE: The data set DEST2.NAMES has 7 observations and 4 variables.  NOTE: Copying HEALTH.PERSONL to DEST2.PERSONL (memtype=DATA).  NOTE: There were 148 observations read from the data set HEALTH.PERSONL.  NOTE: The data set DEST2.PERSONL has 148 observations and 11 variables.  NOTE: Copying HEALTH.PHARM to DEST2.PHARM (memtype=DATA).  NOTE: There were 6 observations read from the data set HEALTH.PHARM.  NOTE: The data set DEST2.PHARM has 6 observations and 3 variables.  NOTE: Copying HEALTH.POINTS to DEST2.POINTS (memtype=DATA).  NOTE: There were 6 observations read from the data set HEALTH.POINTS.  NOTE: The data set DEST2.POINTS has 6 observations and 6 variables.  NOTE: Copying HEALTH.POSTDRUG to DEST2.POSTDRUG (memtype=CATALOG).  NOTE: Copying HEALTH.PRENAT to DEST2.PRENAT (memtype=DATA).  NOTE: There were 149 observations read from the data set HEALTH.PRENAT.  NOTE: The data set DEST2.PRENAT has 149 observations and 6 variables.  NOTE: Copying HEALTH.RESULTS to DEST2.RESULTS (memtype=DATA).  NOTE: There were 10 observations read from the data set HEALTH.RESULTS.  NOTE: The data set DEST2.RESULTS has 10 observations and 5 variables.  NOTE: Copying HEALTH.SLEEP to DEST2.SLEEP (memtype=DATA).  NOTE: There were 108 observations read from the data set HEALTH.SLEEP.  NOTE: The data set DEST2.SLEEP has 108 observations and 6 variables.  NOTE: Copying HEALTH.SYNDROME to DEST2.SYNDROME (memtype=DATA).  NOTE: There were 46 observations read from the data set HEALTH.SYNDROME.  NOTE: The data set DEST2.SYNDROME has 46 observations and 8 variables.  NOTE: Copying HEALTH.TRAIN to DEST2.TRAIN (memtype=DATA).  NOTE: There were 7 observations read from the data set HEALTH.TRAIN.  NOTE: The data set DEST2.TRAIN has 7 observations and 2 variables.  NOTE: Copying HEALTH.WGHT to DEST2.WGHT (memtype=DATA).  NOTE: There were 83 observations read from the data set HEALTH.WGHT.  NOTE: The data set DEST2.WGHT has 83 observations and 13 variables. 

Example 2: Saving SAS Files from Deletion

Procedure features:

  • SAVE statement option:

    • MEMTYPE=

This example uses the SAVE statement to save some SAS files from deletion and to delete other SAS files.

Program

Write the programming statements to the SAS log. SAS option SOURCE writes all programming statements to the log.

 options pagesize=40 linesize=80 nodate pageno=1 source;  libname elder '  SAS-data-library  '; 

Specify the procedure input library to process.

 proc datasets lib=elder; 

Save the data sets CHRONIC, AGING, and CLINICS, and delete all other SAS files (of all types) in the ELDER library. MEMTYPE=DATA is necessary because the ELDER library has a catalog named CLINICS and a data set named CLINICS.

 save chronic aging clinics / memtype=data;  run; 

SAS Log

 41   options pagesize=40 linesize=80 nodate pageno=1 source;  42   libname elder c:\Myfiles\elder;  NOTE: Libref ELDER was successfully assigned as follows:        Engine:        V9        Physical Name: c:\Myfiles\elder  43    proc datasets lib=elder;                                     Directory  Libref          ELDER  Engine          V9  Physical Name   c:\Myfiles\elder  File Name       c:\Myfiles\elder                               Member     File                  #  Name      Type       Size  Last Modified                  1  AGING     DATA       5120   06FEB2003:08:51:21                  2  ALCOHOL   DATA       5120   06FEB2003:08:51:21                  3  BACKPAIN  DATA       5120   06FEB2003:08:51:21                  4  CHRONIC   DATA       5120   06FEB2003:08:51:21                  5  CLINICS   CATALOG   17408   06FEB2003:08:51:21                  6  CLINICS   DATA       5120   06FEB2003:08:51:21                  7  DISEASE   DATA       5120   06FEB2003:08:51:21                  8  GROWTH    DATA       5120   06FEB2003:08:51:21                  9  HOSPITAL  CATALOG   17408   06FEB2003:08:51:21  44       save chronic aging clinics / memtype=data;  45   run;  NOTE: Saving ELDER.CHRONIC (memtype=DATA).  NOTE: Saving ELDER.AGING (memtype=DATA).  NOTE: Saving ELDER.CLINICS (memtype=DATA).  NOTE: Deleting ELDER.ALCOHOL (memtype=DATA).  NOTE: Deleting ELDER.BACKPAIN (memtype=DATA).  NOTE: Deleting ELDER.CLINICS (memtype=CATALOG).  NOTE: Deleting ELDER.DISEASE (memtype=DATA).  NOTE: Deleting ELDER.GROWTH (memtype=DATA).  NOTE: Deleting ELDER.HOSPITAL (memtype=CATALOG). 

Example 3: Modifying SAS Data Sets

Procedure features:

  • PROC DATASETS statement option:

    • NOLIST

  • FORMAT statement

  • INDEX CREATE statement options:

    • NOMISS

    • UNIQUE

  • INFORMAT statement

  • LABEL statement

  • MODIFY statement options:

    • LABEL=

    • READ=

    • SORTEDBY=

  • RENAME statement

This example modifies two SAS data sets using the MODIFY statement and statements subordinate to it. Example 4 on page 381 shows the modifications to the GROUP data set.

Tasks include

  • modifying SAS files

  • labeling a SAS data set

  • adding a READ password to a SAS data set

  • indicating how a SAS data set is currently sorted

  • creating an index for a SAS data set

  • assigning informats and formats to variables in a SAS data set

  • labeling variables in a SAS data set.

  • renaming variables in a SAS data set

Program

Write the programming statements to the SAS log. SAS option SOURCE writes the programming statements to the log.

 options pagesize=40 linesize=80 nodate pageno=1 source;  libname health '  SAS-data-library  '; 

Specify HEALTH as the procedure input library to process. NOLIST suppresses the directory listing for the HEALTH data library.

 proc datasets library=health nolist; 

Add a label to a data set, assign a READ password, and specify how to sort the data. LABEL= adds a data set label to the data set GROUP. READ= assigns GREEN as the read password. The password appears as Xs in the SAS log. SAS issues a warning message if you specify a level of password protection on a SAS file that does not include alter protection. SORTEDBY= specifies how the data is sorted.

 modify group (label='Test Subjects' read=green sortedby=lname); 

Create the composite index VITAL on the variables BIRTH and SALARY for the GROUP data set. NOMISS excludes all observations that have missing values for BIRTH and SALARY from the index. UNIQUE specifies that the index is created only if each observation has a unique combination of values for BIRTH and SALARY.

 index create vital=(birth salary) / nomiss unique; 

Assign an informat and format, respectively, to the BIRTH variable.

 informat birth date7.;  format birth date7.; 

Assign a label to the variable SALARY.

 label salary='current salary excluding bonus'; 

Rename a variable, and assign a label. Modify the data set OXYGEN by renaming the variable OXYGEN to INTAKE and assigning a label to the variable INTAKE.

 modify oxygen;        rename oxygen=intake;        label intake='Intake Measurement';  quit; 

SAS Log

 6    options pagesize=40 linesize=80 nodate pageno=1 source;  7    libname health 'c:\Myfiles\health';  NOTE: Libref HEALTH was successfully assigned as follows:        Engine:        V9        Physical Name: c:\Myfiles\health  8    proc datasets library=health nolist;  9       modify group (label='Test Subjects' read=XXXXX sortedby=lname);  WARNING: The file HEALTH.GROUP.DATA is not ALTER protected.  It could be           deleted or replaced without knowing the password.  10      index create vital=(birth salary) / nomiss unique;  NOTE: Composite index vital has been defined.  11      informat birth date7.;  12      format birth date7.;  13      label salary='current salary excluding bonus';  14      modify oxygen;  15      rename oxygen=intake;  NOTE: Renaming variable oxygen to intake.  16      label intake='Intake Measurement';  17   quit;  NOTE: MODIFY was successful for HEALTH.OXYGEN.DATA.  NOTE: PROCEDURE DATASETS used (Total process time):        real time           16.96 seconds        cpu time            0.73 seconds 

Example 4: Describing a SAS Data Set

Procedure features:

  • CONTENTS statement option:

    • DATA=

Other features:

  • SAS data set option:

    • READ=

This example shows the output from the CONTENTS statement for the GROUP data set. The output shows the modifications made to the GROUP data set in Example 3 on page 378.

Program

 options pagesize=40 linesize=132 nodate pageno=1;  libname health '  SAS-data-library  '; 

Specify HEALTH as the procedure input library, and suppress the directory listing.

 proc datasets library=health nolist; 

Create the output data set GRPOUT from the data set GROUP. Specify GROUP as the data set to describe, give read access to the GROUP data set, and create the output data set GRPOUT, which appears in The OUT= Data Set on page 366.

 contents data=group (read=green) out=grpout;     title 'The Contents of the GROUP Data Set';  run; 

Output

Output 15.9: The Contents of the GROUP Data Set
start example
 The Contents of the GROUP Data Set                                        1                                  The DATASETS Procedure     Data Set Name        HEALTH.GROUP                              Observations          148     Member Type          DATA                                      Variables             11     Engine               V9                                        Indexes               1     Created              Wednesday, February 05, 2003 02:20:56     Observation Length    96     Last Modified        Thursday, February 06, 2003 09:07:54      Deleted Observations  0     Protection           READ                                      Compressed            NO     Data Set Type                                                  Sorted                YES     Label                Test Subjects     Data Representation  WINDOWS_32     Encoding             wlatin1   Western (Windows)                            Engine/Host Dependent Information      Data Set Page Size          8192      Number of Data Set Pages    4      First Data Page             1      Max Obs per Page            84      Obs in First Data Page      62      Index File Page Size        4096      Number of Index File Pages  2      Number of Data Set Repairs  0      File Name                   c:\Myfiles\health\group.sas7bdat      Release Created             9.0101B0      Host Created                XP_PRO                        Alphabetic List of Variables and Attributes   #    Variable    Type    Len    Format     Informat    Label   9    BIRTH       Num       8    DATE7.     DATE7.   4    CITY        Char     15    $.         $.   3    FNAME       Char     15    $.         $.  10    HIRED       Num       8    DATE7.     DATE7.  11    HPHONE      Char     12    $.         $.                            The Contents of the GROUP Data Set                                     2                                  The DATASETS Procedure                        Alphabetic List of Variables and Attributes  #     Variable    Type    Len    Format     Informat    Label  1     IDNUM       Char      4    $.         $.  7     JOBCODE     Char      3    $.         $.  2     LNAME       Char     15    $.         $.  8     SALARY      Num       8    COMMA8.                current salary excluding bonus  6     SEX         Char      1    $.         $.  5     STATE       Char      2    $.         $.                         Alphabetic List of Indexes and Attributes                                                     # of                               Unique    NoMiss    Unique                 #    Index    Option    Option    Values    Variables                 1    vital    YES       YES          148    BIRTH SALARY                                    Sort Information                                  Sortedby       LNAME                                  Validated      NO                                  Character Set  ANSI 
end example
 

Example 5: Concatenating Two SAS Data Sets

Procedure features:

  • APPEND statement options:

    • BASE=

    • DATA=

    • FORCE=

This example appends one data set to the end of another data set.

Input Data Sets

The BASE= data set, EXP.RESULTS.

 The EXP.RESULTS Data Set               1   ID   TREAT    INITWT    WT3MOS   AGE    1   Other    166.28    146.98    35    2   Other    214.42    210.22    54    3   Other    172.46    159.42    33    5   Other    175.41    160.66    37    6   Other    173.13    169.40    20    7   Other    181.25    170.94    30   10   Other    239.83    214.48    48   11   Other    175.32    162.66    51   12   Other    227.01    211.06    29   13   Other    274.82    251.82    31 

The data set EXP.SUR contains the variable WT6MOS, but the EXP.RESULTS data set does not.

 The EXP.SUR Data Set                    2  id      treat     initwt    wt3mos    wt6mos   age  14    surgery     203.60    169.78    143.88    38  17    surgery     171.52    150.33    123.18    42  18    surgery     207.46    155.22       .      41 

Program

 options pagesize=40 linesize=64 nodate pageno=1;  libname exp '  SAS-data-library  '; 

Suppress the printing of the EXP library. LIBRARY= specifies EXP as the procedure input library. NOLIST suppresses the directory listing for the EXP library.

 proc datasets library=exp nolist; 

Append the data set EXP.SUR to the EXP.RESULTS data set. The APPEND statement appends the data set EXP.SUR to the data set EXP.RESULTS. FORCE causes the APPEND statement to carry out the append operation even though EXP.SUR has a variable that EXP.RESULTS does not. APPEND does not add the WT6MOS variable to EXP.RESULTS.

 append base=exp.results data=exp.sur force;  run; 

Print the data set.

 proc print data=exp.results noobs;     title 'The EXP.RESULTS Data Set';  run; 

Output

Output 15.10
start example
 The EXP.RESULTS Data Set              1   ID      TREAT     INITWT    WT3MOS    AGE    1     Other      166.28    146.98    35    2     Other      214.42    210.22    54    3     Other      172.46    159.42    33    5     Other      175.41    160.66    37    6     Other      173.13    169.40    20    7     Other      181.25    170.94    30   10     Other      239.83    214.48    48   11     Other      175.32    162.66    51   12     Other      227.01    211.06    29   13     Other      274.82    251.82    31   14     surgery    203.60    169.78    38   17     surgery    171.52    150.33    42   18     surgery    207.46    155.22    41 
end example
 

Example 6: Aging SAS Data Sets

Procedure features:

  • AGE statement

This example shows how the AGE statement ages SAS files.

Program

Write the programming statements to the SAS log. SAS option SOURCE writes the programming statements to the log.

 options pagesize=40 linesize=80 nodate pageno=1 source;  libname daily '  SAS-data-library  '; 

Specify DAILY as the procedure input library and suppress the directory listing.

 proc datasets library=daily nolist; 

Delete the last SAS file in the list, DAY7, and then age (or rename) DAY6 to DAY7, DAY5 to DAY6, and so on, until it ages TODAY to DAY1.

 age today day1-day7;  run; 

SAS Log

 6  options pagesize=40 linesize=80 nodate pageno=1 source;  7  8     proc datasets library=daily nolist;  9  10        age today day1-day7;  11     run;  NOTE: Deleting DAILY.DAY7 (memtype=DATA).  NOTE: Ageing the name DAILY.DAY6 to DAILY.DAY7 (memtype=DATA).  NOTE: Ageing the name DAILY.DAY5 to DAILY.DAY6 (memtype=DATA).  NOTE: Ageing the name DAILY.DAY4 to DAILY.DAY5 (memtype=DATA).  NOTE: Ageing the name DAILY.DAY3 to DAILY.DAY4 (memtype=DATA).  NOTE: Ageing the name DAILY.DAY2 to DAILY.DAY3 (memtype=DATA).  NOTE: Ageing the name DAILY.DAY1 to DAILY.DAY2 (memtype=DATA).  NOTE: Ageing the name DAILY.TODAY to DAILY.DAY1 (memtype=DATA). 

Example 7: PROC CONTENTS ODS Output

Procedures features:

  • CONTENTS Statement

The example shows how to get PROC CONTENTS output into an ODS output data set for processing.

Program

 title1 "PROC CONTENTS ODS Output";  options nodate nonumber nocenter formdlim='-';  data a;     x=1;  run; 

Use the ODS OUTPUT statement to specify data sets to which CONTENTS data will be directed.

 ods output attributes=atr             variables=var             enginehost=eng; 

Temporarily suppress output to the lst.

 ods listing close;  proc contents data=a;  run; 

Resume output to the lst.

 ods listing;  title2 "all Attributes data";  proc print data=atr noobs;  run;  title2 "all Variables data";  proc print data=var noobs;  run;  title2 "all EngineHost data";  proc print data=eng noobs;  run; 

Select specific data from ODS output.

 ods output attributes=atr1(keep=member cvalue1 label1     where=(attribute in ('Data Representation','Encoding'))     rename=(label1=attribute cvalue1=value))     attributes=atr2(keep=member cvalue2 label2     where=(attribute in ('Observations', 'Variables'))     rename=(label2=attribute cvalue2=value));  ods listing close;  proc contents data=a;  run;  ods listing;  data final;     set atr1 atr2;  run;  title2 "example of post-processing of ODS output data";  proc print data=final noobs;  run;  ods listing close; 
Output 15.11: PROC CONTENTS ODS Output
start example
 PROC CONTENTS ODS Output  all Attributes data  Member    Label1                 cValue1  WORK.A    Data Set Name          WORK.A  WORK.A    Member Type            DATA  WORK.A    Engine                 V9  WORK.A    Created                Thursday, October 10, 2002 00:56:03  WORK.A    Last Modified          Thursday, October 10, 2002 00:56:03  WORK.A    Protection  WORK.A    Data Set Type  WORK.A    Label  WORK.A    Data Representation    WINDOWS_32  WORK.A    Encoding               wlatin1  Western (Windows)                                            c       nValue1    Label2                  Value2         nValue2             .    Observations              1           1.000000             .    Variables                 1           1.000000             .    Indexes                   0                  0    1349873763    Observation Length        8           8.000000    1349873763    Deleted Observations      0                  0             .    Compressed                NO                 .             .    Sorted                    NO                 .             .                                                 0             .                                                 0             .                                                 0  PROC CONTENTS ODS Output  all Variables data  Member    Num    Variable   Type   Len   Pos  WORK.A     1        x       Num      8    0  PROC CONTENTS ODS Output  all EngineHost data  Member    Label1  WORK.A    Data Set Page Size  WORK.A    Number of Data Set Pages  WORK.A    First Data Page  WORK.A    Max Obs per Page  WORK.A    Obs in First Data Page  WORK.A    Number of Data Set Repairs  WORK.A    File Name  WORK.A    Release Created  WORK.A    Host Created  cValue1                                                                     nValue1  4096                                                                    4096.000000  1                                                                          1.000000  1                                                                          1.000000  501                                                                      501.000000  1                                                                          1.000000  0                                                                                 0  C:\DOCUME~1\userid\LOCALS~1\Temp\SAS Temporary Files\_TD3084\a.sas7bdat           .  9.0101B0                                                                          .  XP_PRO                                                                            .  PROC CONTENTS ODS Output  example of post-processing of ODS output data  Member    attribute              value  WORK.A    Data Representation    WINDOWS_32  WORK.A    Encoding               wlatin1   Western (Windows)  WORK.A    Observations           1  WORK.A    Variables              1 
end example
 

For more information on the SAS Output Delivery System, see The Complete Guide to the SAS Output Delivery System .




Base SAS 9.1.3 Procedures Guide (Vol. 1)
Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
ISBN: 1590472047
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net