DATA Step, Macro, Functions and more

can I drop a data var in defined as data in the hash object

Reply
SAS Employee kwu
SAS Employee
Posts: 34

can I drop a data var in defined as data in the hash object

Hi All:


I am creating a datasets using hash. I defined a var1 as part of data in the hash object since I need to use and update it for each hash key for a final calculation and when I out put the hash object using
myhash.output, I would like to drop the var1. however, I can not do

if _n_ = 1 then do;
declare hash myhash();
rc = myhash.definekey('key');
rc = myhash.definedata('data' , 'var1');
myhash.definedone();
call missing(key,data, var1);
end;

......
myhash.output(dataset:"otable(drop=var1)") ;

drop does not work, var1 still be outputed in otable

of course, i can drop the var1 in a separated data step. But I wonder if there is way to use drop statement in the hash.output function?

thanks
karen
Regular Contributor
Posts: 241

Re: can I drop a data var in defined as data in the hash object

It is a known problem. See Problem Note 37287: Data set options not honored by Hash OUTPUT method.



   %put sysvlong=&sysvlong sysscpl=&sysscpl;

   %*-- on log

   sysvlong=9.02.01M0P020508 sysscpl=W32_VSPRO

   --*;

 

   data _null_;

     if 0 then set sashelp.class; 

 

     dcl hash h();

     h.definekey('name');

     h.definedata('name''age');

     h.definedone();

 

     do obs = 1 to nobs;

       set sashelp.class nobs=nobs;

       h.add();

     end;

 

     h.output(dataset: "work.class(drop=age)");

     stop;

   run;

 

   proc print data=class;

   run;

   /* on lst

   Obs    Name       Age

 

     1    John        12

     2    Alice       13

     3    Henry       14

     4    Joyce       11

     5    Janet       15

     6    Judy        14

     7    William     15

     8    Mary        15

     9    James       12

    10    Barbara     13

    11    Carol       14

    12    Ronald      15

    13    Louise      12

    14    Thomas      11

    15    Alfred      14

    16    Robert      12

    17    Jane        12

    18    Philip      16

    19    Jeffrey     13

   */



Message was edited by: chang_y_chung@hotmail.com
SAS Employee kwu
SAS Employee
Posts: 34

Re: can I drop a data var in defined as data in the hash object

Posted in reply to chang_y_chung_hotmail_com
have you tried when the hash h is not defined based on the dataset? In my case, the hash is not defined from a dataset
Regular Contributor
Posts: 241

Re: can I drop a data var in defined as data in the hash object

@kwu: You are right. The drop dsoption in the hash output method does not seem to work. I edited my previous posting.
Super Contributor
Posts: 1,636

Re: can I drop a data var in defined as data in the hash object

Posted in reply to chang_y_chung_hotmail_com

Hi,

Just let you know that the drop option works in sas 9.3.

data _null_;

if 0 then set sashelp.class;

     dcl hash h();

     h.definekey('name');

     h.definedata('name', 'age');

     h.definedone();

    do obs = 1 to nobs;

       set sashelp.class nobs=nobs;

       h.add();

     end;

     h.output(dataset: "work.class(drop=age)");

    stop;

run

;

proc print data=class;

run

;

                                Obs    Name

                                    1    John

                                    2    Alice

                                    3    Henry

                                    4    Joyce

                                    5    Janet

                                    6    Judy

                                    7    William

                                    8    Mary

                                    9    James

                                   10    Barbara

                                   11    Carol

                                   12    Ronald

                                   13    Louise

                                   14    Thomas

                                   15    Alfred

                                   16    Robert

                                   17    Jane

                                   18    Philip

                                   19    Jeffrey

Linlin

Ask a Question
Discussion stats
  • 4 replies
  • 168 views
  • 0 likes
  • 3 in conversation