Example 4. DTS: Transferring Generations of SAS Data Sets

Purpose

Generation data sets are historical versions of SAS data sets, SAS views, and SAS/ACCESS files. They enable you to keep a historical record of the changes that you make to these files. There are two data set options that are useful when manipulating generations of SAS data sets: GENMAX (maximum number of generations) and GENNUM (generation number). GENMAX specifies how many generations to keep, and GENNUM is used to access a specific version of a generation group.
SAS/CONNECT transfers generations of SAS data sets by default during library transfers. The base data set, as well as all of its historical versions, are transferred.
If you do not want all generations to be transferred, you should do one of the following:
  • transfer a library using the GEN=NO option.
  • transfer single data sets. Only the specified data set is transferred.

Example 4.1: Using LIBRARY Transfers to Transfer Data Set Generations

This example transfers the client data set LOCAL.SALES as well as its generations to the server library REMOTE. If the data set SALES already exists in the output library, the base and all existing generations are deleted and replaced by those that are uploaded.
data local.sales(genmax=3);
   input store sales95 sales96 sales97;
   datalines;
  1   221325.85   214664.02   212644.60
  2   134511.96   159369.47   317808.48
  3   321662.42   244789.33   236782.59
 ;
run;

data local.sales;
   input store sales95 sales96 sales97;
   datalines;
  1   251325.25   217662.16   222614.60
  2   144512.11   179369.47   327808.48
  3   329682.43   249989.93   256782.59
 ;
run;

data local.sales;
   input store sales95 sales96 sales97;
   datalines;
  1   261325.33   218862.16   222614.60
  2   145012.11   189339.47   328708.71
  3   330682.46   259919.92   258722.52
 ;
run;

   /* PROC DATASETS will show that the   */
   /* base data set as well as two       */
   /* generations exist in the library.  */
proc datasets lib=local;
quit;

rsubmit;
   proc upload in=local out=remote cstatus=no;
   run;
endrsubmit;

Example 4.2: Using a SELECT Statement to Transfer Generations

Specific generations of data sets cannot be specified in the SELECT or the EXCLUDE statements for library transfers. When the SELECT statement is specified for the library transfer, the selected base data set as well as all of its historical versions are transferred. Similarly, when the EXCLUDE statement is specified for the library transfer and the GEN=NO option is not specified, the selected base data set as well as all of its historical versions are excluded from the transfer.
In the following example, the data set LOCAL.SALES as well as all of its generations are uploaded.
libname local 'work' $loglib=yes;
data sales(genmax=3); x=1; run;
data sales; x=2; run;
data sales ; x=3; run;
data x; x=1; run;
rsubmit status=no;
   proc upload in=local out=remote cstatus=no;
      select sales (mt=data);
   run;
endrsubmit;

Example 4.3: Inheriting Generation Specific Attributes

During library transfers and single data set transfers when OUT= is not specified, data set attributes are inherited in the output data set. In SAS releases after SAS 6, the maximum number of generations is a new inherited attribute. In addition, the next generation number attribute is inherited ONLY when a library transfer occurs. This attribute is inherited only when the generations are actually transferred, and therefore it is NOT inherited for any single data set transfers. In the following example, both the maximum number of generations and the next generation number attributes are inherited in the output data set, because this is a library transfer.
rsubmit;
   proc download in=remote out=local;
      select sales(mt=data);
   run;
endrsubmit;
In the following example, only the maximum number of generations attribute is inherited. The next generation number attribute is not inherited, because this is a single data set transfer, and therefore no generations are transferred.
rsubmit;
   proc download data=remote.sales;
   run;
endrsubmit;

Example 4.4: Transferring Single Data Sets

A specific generation of data set can be transferred by specifying the GENNUM= data set option for a single data set transfer. In the following example, a specific historical version is uploaded by specifying GENNUM=1.
rsubmit;
   proc upload data=local.sales(gennum=1);
   run;
endrsubmit;