BookmarkSubscribeRSS Feed
kwu
SAS Employee kwu
SAS Employee
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
4 REPLIES 4
chang_y_chung_hotmail_com
Obsidian | Level 7
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
kwu
SAS Employee kwu
SAS Employee
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
chang_y_chung_hotmail_com
Obsidian | Level 7
@kwu: You are right. The drop dsoption in the hash output method does not seem to work. I edited my previous posting.
Linlin
Lapis Lazuli | Level 10

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

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1206 views
  • 0 likes
  • 3 in conversation