Chapter Contents |
Previous |
Next |
Definition of Generation Data Sets |
You can request generations for both SAS data files and SAS data views; however, there are differences:
Note: Generation data sets provide historical versions of a data set;
they do not track observation updates for an individual data set.
Terminology |
The following terms are relevant to generation data sets:
Invoking Generation Data Sets |
data a(genmax=4); x=1; output; run;
Once generations is in effect, the data set member name is limited to 28 characters (rather than 32), because the last four characters are reserved for a version number. When generations is not in effect (that is, GENMAX=0), the member name can be up to 32 characters. See the GENMAX= data set option in SAS Language Reference: Dictionary.
If a password is assigned, all files within a generation group must have the same password. SAS automatically applies any password that you assign to the base version to all of the versions in the group.
Maintaining a Generation Group |
A | base (current) version |
A#003 | most recent (youngest) historical version |
A#002 | second most recent historical version |
A#001 | oldest historical version. |
With GENMAX=4, a fourth replacement deletes the oldest version, which is A#001. As replacements occur, SAS will always maintain four copies. For example, after ten replacements, the result is:
A | base (current) version |
A#010 | most recent (youngest) historical version |
A#009 | 2nd most recent historical version |
A#008 | oldest historical version |
The limit for version numbers that SAS can append is #999. That is, after 999 replacements, the youngest version is #999. After 1,000 replacements, SAS rolls over the youngest version number to #000. After 1,001 replacements, the youngest version number is #001. For example, using data set A with GENNUM=4, the results would be:
999 replacements |
|
1,000 replacements |
|
1,001 replacements |
|
The following figure shows how names are assigned to generation data sets:
Time | SAS Code | Data Set Name(s) | GENNUM= Absolute Reference | GENNUM= Relative Reference | Explanation |
---|---|---|---|---|---|
1 | data air (genmax=3); | AIR | 1 | 0 | AIR data set created at time 1, and three generations requested |
2 | data air; | AIR AIR#001 |
2 1 |
0 -1 |
New AIR is created at time 2. AIR from time 1 is renamed AIR#001. |
3 | data air; | AIR AIR#002 AIR#001 |
3 2 1 |
0 -1 -2 |
New AIR is created at time 3. AIR from time 2 is renamed AIR#002. |
4 | data air; | AIR AIR#003 AIR#002 |
4 3 2 |
0 -1 -2 |
New AIR is created at time 4. AIR from time 3 is renamed AIR#003. AIR#001 from time 1, which is the oldest, is deleted. |
5 | data air (genmax=2); | AIR AIR#004 |
5 4 |
0 -1 |
New AIR is created at time 5, and the number of generations is changed to two. AIR from time 4 is renamed AIR#004. The two oldest versions are deleted. |
Processing Specific Versions of a Generation Group |
proc print data=a; run;
To request a specific version from a generation group, use the GENNUM= input data set option. There are two methods that you can use:
proc print data=a(gennum=3); run;
Note: After 1,000 replacements, if you want historical version
#000, specify GENNUM=1000.
proc print data=a(gennum=-3); run;
This SAS statement ... | produces this result ... | |
---|---|---|
proc print data=air(gennum=0);
|
Prints the current (base) version of the AIR data set. | |
proc print data=air(gennum=-2); |
Prints the version two generations back from the current version. | |
proc print data=air(gennum=3); |
Prints the file AIR #003. | |
proc print data=air(gennum=1000); |
After 1,000 replacements, prints the file AIR#000, which is the file that is created after AIR #999. |
Managing Generation Data Sets |
In addition, you can display the contents for an individual historical
version.
libname mylib1 'SAS-data-library1'; libname mylib2 'SAS-data-library2'; proc datasets; copy in=mylib1 out=mylib2; select mygen1; run;
You can use the GENNUM= data set option to append a specific historical version. For example, the following DATASETS procedure uses the APPEND statement to append a historical version of data set B to data set A. Note that by default, SAS uses the base version for the BASE= data set.
proc datasets; append base=a data=b(gennum=2); run;
modify a(genmax=3);
You can also use the MODIFY statement of the DATASETS procedure to modify the number of generations on an existing file:
libname mylib SAS-data-library; proc datasets lib=mylib; modify air(genmax=4); run;
When deleting data sets, you can delete a specific version as well as delete an entire generation group. The following table shows the types of delete operations and effects on generation data sets when you delete versions of a generation group. For this data set, assume that the base version of AIR and two historical versions (AIR#001 and AIR#002) exist already for each command.
These SAS statements in PROC DATASETS ... | produce this result ... | |
---|---|---|
delete air;
|
Deletes the base version and shifts up historical versions. AIR#002 is renamed to AIR and becomes the new base version. | |
delete air(gennum=2); |
Deletes AIR#002. | |
delete air(gennum=-2); |
Deletes the second youngest version (AIR#001). If the referenced file does not exist, this causes an error. | |
delete air(gennum=all); |
Deletes all data sets in the generation group, including the base file. | |
delete air(gennum=hist); |
Deletes all data sets in the generation group, except the base file. |
A complete set of GENNUM= specifications is listed under the DATASETS
procedure, DELETE statement, in the SAS Language Reference: Dictionary.
When renaming a data set, you can rename an entire generation group:
change a=newa;Or you can rename a single copy using the CHANGE statement in PROC DATASETS. Note that if the single copy is the base (gennum=0), the youngest historical version automatically becomes the base.
change a(gennum=2)=newa;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.