BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Good morning. I would like to use the "output" method of hash sas, but I need to add the "key" column and display it on the "class_hash" output dataset. I can't figure out how to do it. I give the example:

data large;
   if 0 then set sashelp.class;
   declare hash obj(dataset: 'sashelp.class', multidata:'y');
   obj.definekey ("name" );
   obj.defineData(all:'yes');
   obj.definedone();
   length key $ 200;
   key = catt(name,sex);
   obj.output(dataset:'class_hash');
   stop;
run;

Mario

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Loading and then writing a hash table is still a read/write operation so for your use case wouldn't offer any advantage over a simple data step.

 

Using the hash object offers often real advantages for lookups as it helps to avoid sorts.

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

The output method can only output what's in the hash defined as data. 

The hash key column name is with all:"yes" also part of the data and will be included.

 

Column key which you create in your SAS data step is not in the hash table and though not available when writing the hash table in memory to disk.

 

Not sure if that's going to be of any use for your real use case but below one option how to add another variable to the hash.

data v_demo / view=v_demo;
  set sashelp.class;
   length key $ 200;
   key = catt(name,sex);
run;

data large;
   if 0 then set v_demo;
   declare hash obj(dataset: 'v_demo', multidata:'y');
   obj.definekey ("name" );
   obj.defineData(all:'yes');
   obj.definedone();
   length key $ 200;
   key = catt(name,sex);
   obj.output(dataset:'class_hash');
   stop;
run;

proc print data=class_hash;
run;

 

 

mariopellegrini
Pyrite | Level 9

Thank you, but this way I don't get any advantage in terms of processing time. I was hoping you could save processing time compared to a simple data or proc sql step, using hash "output" method

Patrick
Opal | Level 21

Loading and then writing a hash table is still a read/write operation so for your use case wouldn't offer any advantage over a simple data step.

 

Using the hash object offers often real advantages for lookups as it helps to avoid sorts.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 482 views
  • 3 likes
  • 2 in conversation