BookmarkSubscribeRSS Feed
gyambqt
Obsidian | Level 7

Hello Experts,

When I create a hash table, I have to specify the key value, but if I want to replace the key value with a new variable created during the hash iterator process within the same data step. How do I do that?

For the code below, I want the dataset work.temp1(highlighted in red) to be created  before it hold by "mylittlehash1" ,how do I achieve that?

My goal is to use one single datastep (with hash) to complete the task as shown in the code below.

data work.temp1 work.temp2;
attrib filename length=$1000
sfname length=$1000
key length=$1000;

if _n_=1 then do;
declare hash mylittlehash(dataset: 'library.want', ordered:'yes');
declare hiter mylittlehashter('mylittlehash');
mylittlehash.defineData('filename');
mylittlehash.defineKey('sfname');
mylittlehash.defineDone();
call missing(filename,sfname,key);
end;
rc=mylittlehashter.first();
do until (rc ne 0);
perlexpression2=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");
if prxmatch(perlexpression2,filename) then do;
Key=upcase((prxposn(perlexpression2,1,filename)));
output work.temp1;
rc=mylittlehashter.next();
end;
end;


declare hash mylittlehash1(dataset: 'work.temp1', ordered:'yes', duplicate: 'r');
mylittlehash1.defineKey('key');
mylittlehash1.defineData('key');
mylittlehash1.defineDone();
end;

set files_found;
perlexpression=prxparse("/\w*(\w\w\d\d\d\d)(\w)\w*/");
if prxmatch(perlexpression,filename) then do;
Key=upcase((prxposn(perlexpression,1,filename)));
end;

if prxposn(perlexpression,2,filename)="Z";
rc=mylittlehash1.check();
if rc=0 then output work.temp2;

run;

Thanks

1 REPLY 1
Patrick
Opal | Level 21

Please post your questions only once into a single forum. My reply given here

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 544 views
  • 0 likes
  • 2 in conversation