Usage Note 24547: Adding a new variable to a hash table when using the DATASET: argument tag in the DECLARE statement
When the hash object is created and the DATASET: argument tag is used, the data variables must exist in the input data set.
If you have an additional variable that you want to specify in a DEFINEKEY or DEFINEDATA method, you can either
a) Load the data set into the hash table manually using the ADD() method rather than with the DATASET: argument tag. For example:
data new;
if _n_ = 1 then do;
if 0 then set sashelp.class; /* Add variables from the view */
/* to the PDV for WORK.NEW */
declare hash ht();
ht.definekey ('name','teacher');
ht.definedata('name','teacher','age');
ht.definedone();
end;
do while(not last);
set sashelp.class end=last;
teacher=' ';
rc=ht.add();
end;
...;
run;
OR
b) Create a view using the existing data set plus the new variable. Use the view in the DATASET: argument tag. For example:
/* Create a view of the desired data set plus the additional variable */
data class_vw/view=class_vw;
retain teacher ' ';
set sashelp.class(keep = name age);
run;
data new;
if _n_ = 1 then do;
if 0 then set class_vw; /* Add variables from the view to */
/* the PDV for WORK.NEW */
declare hash ht(dataset: 'class_vw');
ht.definekey ('name','teacher');
ht.definedata('name','teacher','age');
ht.definedone();
end;
...
run;
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
| Type: | Usage Note |
| Priority: | low |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects Common Programming Tasks ==> Reading and Writing SAS Data
|
| Date Modified: | 2019-07-15 08:59:29 |
| Date Created: | 2006-11-28 13:21:01 |