Concatenate specific data sets in a generation group of data sets.
Featured Step | PROC APPEND
DATA step PROC SQL |
Featured Step Options and Statements | GENNUM= option |
A library system maintains daily circulation records for the main library. The system maintains copies of the daily records for three days. It adds the daily records to a monthly data set daily after closing.
CITYLIB.MAINLIB_DAILY (GENNUM=-2) Obs circdate type adult juvenile youngpeople 1 03/06/2010 Audiocassettes 16 7 5 2 03/06/2010 CompactDiscs 111 78 11 3 03/06/2010 HardcoverFiction 31 4 1 4 03/06/2010 HardcoverNonfiction 236 87 18 5 03/06/2010 LargeTypeFiction 10 0 0 6 03/06/2010 LargeTypeNonfiction 16 0 0 7 03/06/2010 PaperbackFiction 213 159 134 8 03/06/2010 PaperbackNonfiction 44 24 15 9 03/06/2010 PeriodicalsLargeType 0 0 0 10 03/06/2010 Periodicals 161 33 5 11 03/06/2010 AudioBooksFiction 40 21 3 12 03/06/2010 AudioBooksNonfiction 43 4 4 13 03/06/2010 DVDFiction 6 3 12 14 03/06/2010 DVDNonfiction 51 6 1
Assume the display of data set CITYLIB. MAINLIB_DAILY was produced after the library closed on March 8, 2010. Two versions back correspond to March 6, 2010. The first list shows the observations in the daily data set for March 6, 2010. The second list shows the observations in the daily data set for March 7, 2010. The third list shows the observations in the daily data set for March 8, 2010.
CITYLIB.MAINLIB_DAILY (GENNUM=-1) Obs circdate type adult juvenile youngpeople 1 03/07/2010 Audiocassettes 20 7 5 2 03/07/2010 CompactDiscs 117 81 11 3 03/07/2010 HardcoverFiction 28 6 2 4 03/07/2010 HardcoverNonfiction 216 76 18 5 03/07/2010 LargeTypeFiction 11 0 0 6 03/07/2010 LargeTypeNonfiction 15 0 0 7 03/07/2010 PaperbackFiction 216 166 140 8 03/07/2010 PaperbackNonfiction 47 33 14 9 03/07/2010 PeriodicalsLargeType 0 0 0 10 03/07/2010 Periodicals 178 35 6 11 03/07/2010 AudioBooksFiction 40 22 3 12 03/07/2010 AudioBooksNonfiction 44 4 3 13 03/07/2010 DVDFiction 16 15 8 14 03/07/2010 DVDNonfiction 52 6 1
The daily data sets have the same variables. Each daily data set has 14 observations, one for each category of material circulated. These categories are maintained in all data sets. The monthly data set has an observation for each category on each day in the month.
CITYLIB.MAINLIB_DAILY (GENNUM=0) Obs circdate type adult juvenile youngpeople 1 03/08/2010 Audiocassettes 18 7 5 2 03/08/2010 CompactDiscs 110 72 10 3 03/08/2010 HardcoverFiction 35 3 2 4 03/08/2010 HardcoverNonfiction 206 86 17 5 03/08/2010 LargeTypeFiction 11 0 0 6 03/08/2010 LargeTypeNonfiction 16 0 0 7 03/08/2010 PaperbackFiction 231 162 142 8 03/08/2010 PaperbackNonfiction 41 34 12 9 03/08/2010 PeriodicalsLargeType 0 0 0 10 03/08/2010 Periodicals 177 35 5 11 03/08/2010 AudioBooksFiction 44 19 3 12 03/08/2010 AudioBooksNonfiction 39 4 3 13 03/08/2010 DVDFiction 13 13 6 14 03/08/2010 DVDNonfiction 55 6 1
Output 8.17 SAS Log with PROC DATASETS Report Produced after Library Closing March 8, 20101001 proc datasets library=cmds; Directory Libref CITYLIB Engine V9 Physical Name q:citylibcirculationdatasets File Name q: citylibcirculationdatasets Gen Member File # Name Num Type Size Last Modified 1 MAINLIB_2010 DATA 46080 01Mar10:02:03:50 2 MAINLIB_2010 1 DATA 46080 01Feb10:01:49:40 3 MAINLIB_DAILY DATA 9216 08Mar10:21:43:52 4 MAINLIB_DAILY 65 DATA 9216 06Mar10:21:59:03 5 MAINLIB_DAILY 66 DATA 9216 07Mar10:21:13:25 6 MAINLIB_FEB2010 DATA 25600 28Feb10:23:04:52 7 MAINLIB_FEB2010 21 DATA 25600 22Feb10:23:18:11 8 MAINLIB_FEB2010 22 DATA 25600 23Feb10:23:59:25 9 MAINLIB_FEB2010 23 DATA 25600 24Feb10:23:43:52 10 MAINLIB_FEB2010 24 DATA 25600 25Feb10:23:31:10 11 MAINLIB_FEB2010 25 DATA 25600 26Feb10:23:29:04 12 MAINLIB_FEB2010 26 DATA 25600 27Feb10:23:21:27 13 MAINLIB_JAN2010 DATA 25600 31Jan10:23:10:19 14 MAINLIB_JAN2010 24 DATA 25600 25Jan10:23:14:55 15 MAINLIB_JAN2010 25 DATA 25600 26Jan10:23:26:46 16 MAINLIB_JAN2010 26 DATA 25600 27Jan10:23:52:33 17 MAINLIB_JAN2010 27 DATA 25600 28Jan10:23:49:24 18 MAINLIB_JAN2010 28 DATA 25600 29Jan10:23:43:08 19 MAINLIB_JAN2010 29 DATA 25600 30Jan10:23:43:12 20 MAINLIB_MAR2010 DATA 13312 09Mar10:23:51:24 21 MAINLIB_MAR2010 2 DATA 9216 03Mar10:23:23:19 22 MAINLIB_MAR2010 3 DATA 9216 04Mar10:23:38:55 23 MAINLIB_MAR2010 4 DATA 9216 05Mar10:23:21:48 24 MAINLIB_MAR2010 5 DATA 13312 06Mar10:23:43:30 25 MAINLIB_MAR2010 6 DATA 13312 07Mar10:23:48:26 26 MAINLIB_MAR2010 7 DATA 13312 08Mar10:23:21:52 1002 quit; |
The code in this example shows how to reference specific versions of generation data sets. Data set MAINLIB_DAILY is a generation data set that was defined to have three generations (GENMAX=3). It maintains the daily circulation records for a library.
This data set is started on January 2 of the year and is updated every day the library is open. Assume that the list of data sets in the CITYLIB library is made after closing on March 8, 2010. The base version of MAINLIB_DAILY is for that day's circulation records. The most recent historical version is for March 7, and the next most recent historical version is for March 6.
The code that follows combines the three MAINLIB_DAILY generation data sets into one data set MOSTRECENT3. It shows first how you can reference the data sets by their absolute version number, which is the version that is listed in the PROC DATASETS output in Output 8.17. Secondly, it shows how to reference the data sets by their relative version number.
The data sets are combined three ways: by PROC APPEND, by the DATA step, and by PROC SQL.
The following code samples concatenate the three data sets in the MAINLIB_DAILY generation group in chronological order. The oldest of the three data sets contains records for March 6, the second oldest contains records for March 7, and the third contains records for March 8.
The code in the left column for each code section references the data sets relatively where 0 means the current version, -1 means the next most recent version (one generation back), and -2 means the second most recent version (two generations back).
The code in the right column references the data sets by using the version number that is assigned to the data set. The version numbers can be found by referring to the list in Output 8.17.
When referencing the base version of the data set, you can omit the GENNUM= option. By default, when you omit a generation number, SAS interprets that you mean the most recent generation data set. The relative generation number for the base data set is 0 while the absolute generation number depends on how many previous versions have been created. In this example, the data for March 8th are stored in the 67th version of MAINLIB_DAILY.
The code samples in Table 8.3 use PROC APPEND to concatenate the three data sets in chronological order. It starts by deleting the output data set MOSTRECENT3 in library CITYLIB. If that data set already existed, the PROC APPEND steps would add to this existing data set.
Use PROC APPEND when you have the same variables in the group of data sets you're appending, which is the situation in this example. If you have different variables or same-named variables with different attributes, the steps might not execute as expected, and you might receive errors or warnings. For more information about restrictions in using PROC APPEND, see SAS documentation.
Relative Generation Number proc datasets library=citylib nolist; delete mostrecent3; run; quit; proc append base=mostrecent3 data=citylib.mainlib_daily (gennum=-2); run; proc append base=mostrecent3 data=citylib.mainlib_daily (gennum=-1); run; proc append base=mostrecent3 data=citylib.mainlib_daily (gennum=0); run; | Absolute Generation Number proc datasets library=work nolist; delete mostrecent3; run; quit; proc append base=mostrecent3 data=citylib.mainlib_daily (gennum=65); run; proc append base=mostrecent3 data=citylib.mainlib_daily (gennum=66); run; proc append base=mostrecent3 data=citylib.mainlib_daily (gennum=67); run; |
The code samples in Table 8.4 use the DATA step to concatenate the three generation data sets in generation group MAINLIB_DAILY in chronological order.
Relative Generation Number data mostrecent3; set citylib.mainlib_daily(gennum=-2) citylib.mainlib_daily(gennum=-1) citylib.mainlib_daily(gennum=0); run; | Absolute Generation Number data mostrecent3; set citylib.mainlib_daily(gennum=65) citylib.mainlib_daily(gennum=66) citylib.mainlib_daily(gennum=67); run; |
The code samples in Table 8.5 use the UNION operator in PROC SQL to combine the three generation tables in generation group MAINLIB_DAILY in chronological order.
Relative Generation Number proc sql; create table mostrecent3 as select * from citylib.mainlib_daily (gennum=-2) union select * from citylib.mainlib_daily (gennum=-1) union select * from citylib.mainlib_daily (gennum=0); quit; | Absolute Generation Number proc sql; create table mostrecent3 as select * from citylib.mainlib_daily (gennum=65) union select * from citylib.mainlib_daily (gennum=66) union select * from citylib.mainlib_daily (gennum=67); quit; |
3.19.54.149