BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jakkas
Calcite | Level 5

Something interesting is happening when I am trying to create a hash table from a table with no rows. In the following example Temp1 has no rows, Temp2 has one row. I would expect Temp3 to have one row with missing value for x. But Temp3 has no rows. I have this logic in a big data step with multiple hash tables and as soon as one of the hash table input talbe is empty all the subsequent ones fail to load and nothing is written to output tables in the data step. Anyone know why this happens and how to control it? Thank you.

Proc Sql;

     Create Table Temp1 (P Char(1), x Num);

Quit;

Data Temp2;

     P="A"; y=3; Output;

Run;

Data Temp3(Drop=rc);

     Declare Hash myhash();

     myhash.DefineKey('P');

     myhash.DefineData('x');

     myhash.DefineDone();

     eof=0;

     Do Until(eof);

          Set Temp1 end=eof;

          rc=myhash.add();

     End;

     eof=0;

     Do Until(eof);

          Set Temp2 end=eof;

          rc=myhash.find();

          output;

     End;

     Stop;

Run;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Do while NOT and use different END variables.

Proc Sql;
  
Create Table Temp1 (P Char(1), x Num);
   Quit;


Data Temp2;
   p="A"; y=3; Output;
  
Run;


Data Temp3(Drop=rc);
   Declare Hash myhash();
   myhash.DefineKey('P');
   myhash.DefineData('x');
   myhash.DefineDone();
  
Do while(not eof1);
      Set Temp1 end=eof1;
      rc=myhash.add();
     
End;
  
Do while(not eof2);
      Set Temp2 end=eof2;
      rc=myhash.find();
     
output;
     
End;
  
Stop;
  
Run;
proc print data=temp3;
   run;

View solution in original post

1 REPLY 1
data_null__
Jade | Level 19

Do while NOT and use different END variables.

Proc Sql;
  
Create Table Temp1 (P Char(1), x Num);
   Quit;


Data Temp2;
   p="A"; y=3; Output;
  
Run;


Data Temp3(Drop=rc);
   Declare Hash myhash();
   myhash.DefineKey('P');
   myhash.DefineData('x');
   myhash.DefineDone();
  
Do while(not eof1);
      Set Temp1 end=eof1;
      rc=myhash.add();
     
End;
  
Do while(not eof2);
      Set Temp2 end=eof2;
      rc=myhash.find();
     
output;
     
End;
  
Stop;
  
Run;
proc print data=temp3;
   run;

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!

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