Processing Generation Data Sets

Overview

Once you have a generation group that contains more than one generation data set, you might want to select a particular data set to process. To select a particular generation, you use the GENNUM= data set option.
General form, GENNUM= data set option:
GENNUM=n
Here is an explanation of the syntax:
n
specifies a particular historical version of a data set:
  • n>0 is an absolute reference to a historical version by its generation number.
  • n<0 is a relative reference to a historical version.
  • n=0 is the current version.

Examples

To print the current version of the data, you do not need to use the GENNUM= option. Simply use code such as the following:
proc print data=year;
run;
To print the youngest historical version, you have several choices. You can specify either the absolute or relative reference in the GENNUM= option, as shown:
proc print data=year(gennum=4);  /*absolute reference*/
run;
proc print data=year(gennum=-1);  /*relative reference*/
run;
You can also view information about a specific generation using the GENNUM= option with PROC CONTENTS, as shown:
proc contents data=year(gennum=-1);  /*relative reference*/
run;
Now that you have seen a few examples of using the GENNUM= option, consider how generation numbers change.

How Generation Numbers Change

When you use the GENNUM= option, you can refer to either the absolute or relative generation number. It is helpful to understand how generation numbers change so that you can identify the generation that you want to process.
First, consider how SAS names generation data sets. The first time a data set with generations in effect is replaced, SAS keeps the replaced data set, and appends a four-character version number to its member name. The name includes the pound symbol (#) and a three-digit number. That is, for a data set named A, the replaced data set becomes A#001. When the data set is replaced for the second time, the replaced data set becomes A#002. That is, A#002 is the version that is chronologically closest to the base version. The table below shows the result after three replacements.
Data Set Name
Explanation
A
base (current) version
A#003
most recent (youngest) historical version
A#002
second most recent historical version
A#001
oldest historical version
The limit for version numbers that SAS can append is #999. After 1000 replacements, SAS rolls over the youngest version number to #000.
Now we consider how absolute and relative generation numbers (specified on the GENNUM= option) change. Each time SAS creates a new generation, the absolute generation number increases sequentially. As older generations are deleted, their absolute generation numbers are retired.
In contrast, the relative generation number always refers to generations in relation to the base generation. The base or current generation is always 0 and -1 is the youngest historical version.
The following table shows data set names and their absolute and relative GENNUM= numbers.
Table 18.6 Data Set Names with GENNUM= Numbers
Iteration
SAS Code
Data Set Names
GENNUM=Absolute Reference
GENNUM=Relative Reference
Explanation
1
data Year (genmax=3);
Year
1
0
The data set Year is created, and three generations are requested.
2
data Year;
Year
Year#001
2
1
0
-1
Year is replaced. Year from iteration 1 is renamed Year#001.
3
data Year;
Year
Year#002
Year#001
3
2
1
0
-1
-2
Year is replaced. Year from iteration 2 is renamed Year#002.
4
data Year;
Year
Year#003
Year#002
4
3
2
0
-1
-2
Year is replaced. Year from iteration 3 is renamed Year#003. Year#001 from iteration 1, which is the oldest, is deleted.
5
data Year (genmax=2);
Year
Year#004
5
4
0
-1
Year is replaced, and the number of generations is changed to 2. Year from iteration 4 is renamed Year#004. The two oldest versions are deleted.
You have learned that you use PROC DATASETS to initiate generation data sets on an existing SAS data set. Once you have created generation data sets, you can use PROC DATASETS to perform management tasks such as the following:
  • deleting all or some of the generations
  • renaming an entire generation group or any member of the group to a new base name.
General form, PROC DATASETS with the CHANGE and DELETE statements:
PROC DATASETS LIB=libref <NOLIST>;
CHANGE SAS-data-set<(GENNUM=n)>=new-data-set-name;
DELETE SAS-data-set<(GENNUM=n | HIST | ALL)>;
QUIT;
Here is an explanation of the syntax:
libref
is the library that contains the data that you want to modify.
NOLIST
suppresses the directory listing.
SAS-data-set
is the name of the SAS data set you want to change or delete.
new-data-set-name
is the new name for the SAS data set in the CHANGE statement.
n
is the absolute or relative reference to a generation number.
HIST
refers to all generations except the base version.
ALL
refers to the base version and all generations.

Examples

The following code uses the CHANGE statement to rename the data set SalesData to Sales. If generations have been created, the base name of all generations is renamed.
proc datasets library=quarter1 nolist;
   change salesData=sales;
quit;
The following code uses the GENNUM= option to rename only the second historical data set:
proc datasets library=quarter1 nolist;
   change sales(gennum=2)=newsales;
quit;
The following code deletes one historical version. This action might leave a hole in the generation group.
proc datasets library=quarter1 nolist;
   delete newsales(gennum=-1);
quit;
When you use the GENNUM= option with the DELETE statement, you can use the HIST and ALL keywords. The following code uses the HIST keyword to delete all of the historical versions:
proc datasets library=quarter1 nolist;
   delete newsales(gennum=HIST);
quit;
The following code uses the ALL keyword in the GENNUM= option to delete all of the SAS data sets in a generation group:
proc datasets library=quarter1 nolist;
   delete newsales(gennum=ALL);
quit;
Tip
For more information about using the DATASETS procedure to process data, see the SAS documentation.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.57.126