DATASETS Procedure

Example 6: Concatenating Two SAS Data Sets

Features:
APPEND statement options:
BASE=
DATA=
FORCE=

Program

          
           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 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 Description

This example appends one data set to the end of another data set.
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-library';
proc datasets library=exp nolist;
   append base=exp.results data=exp.sur force;
run;
proc print data=exp.results noobs;
   title 'The EXP.RESULTS Data Set';
run;

Program Description

options pagesize=40 linesize=64 nodate pageno=1;
LIBNAME exp 'SAS-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
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