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

Hello Everyone,

I have a problem where I need to create three separate hash objects and then use them all together in a query in order to pull information.

I am not having  problem with getting all of my information from my hash objects except for one.

Here is my code:

data billing (keep=Customer_ID Customer_Name Customer_Country Country_Name Product_ID Product_Name Order_Date Quantity Total_Retail_Price);

  length Customer_ID 8. Order_Date 8. Product_ID 8. Quantity 8. Total_Retail_Price 8. Product_ID 8. Product_Name $50

         Customer_Country $5 Customer_Name $50 Country $5 Country_Name $25;

  if _N_=1 then do;

  declare hash P(dataset:'orion.product_list');

  P.definekey('Product_ID');

  P.definedata('Product_Name');

  P.definedone();

  declare hash D(dataset:'orion.customer_dim');

  D.definekey('Customer_ID');

  D.definedata('Customer_Country','Customer_Name');

  D.definedone();

  declare hash C(dataset:'orion.country');

  C.definekey('Country');

  C.definedata('Country_Name');

  C.definedone();

  call missing(Product_ID, Product_Name, Customer_ID, Customer_Country, Customer_Name, Country, Country_Name);

  end;

  set orderfact;

  rc1=P.find(key:Product_ID);

  rc2=D.find(key:Customer_ID);

  rc3=C.find(key:Country);

run;

The hash object that I am having difficulty in returning is the Country_Name.

I am not sure where my code is going wrong, but if someone could take a look at it and let me know where I am going wrong it would be greatly appreciated.

Thank you!

Alisa

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Hi Alisa,

Not knowing your log message and what exactly being included in 4 of your inputting data set , I am not 100% sure about your problem, but my bet is that 'orderfact' does not have variable 'Country', instead, it has 'Customer_Country'. If that is the case, then it is an easy fix.

data billing (keep=Customer_ID Customer_Name Country Country_Name Product_ID Product_Name Order_Date Quantity Total_Retail_Price rename=country=Customer_Country);

  length Customer_ID 8. Order_Date 8. Product_ID 8. Quantity 8. Total_Retail_Price 8. Product_ID 8. Product_Name $50

         Customer_Country $5 Customer_Name $50 Country $5 Country_Name $25;

  if _N_=1 then do;

  declare hash P(dataset:'orion.product_list');

  P.definekey('Product_ID');

  P.definedata('Product_Name');

  P.definedone();

  declare hash D(dataset:'orion.customer_dim');

  D.definekey('Customer_ID');

  D.definedata('Customer_Country','Customer_Name');

  D.definedone();

  declare hash C(dataset:'orion.country');

  C.definekey('Country');

  C.definedata('Country_Name');

  C.definedone();

  call missing(Product_ID, Product_Name, Customer_ID, Customer_Name, Country, Country_Name);

  end;

  set orderfact (rename=Customer_Country=country);

rc1=P.find();

  rc2=D.find();

  rc3=C.find();

run;

BTW, key name does not need to be spelled out explicitly in find() method.

Good Luck,

Haikuo

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

Hi Alisa,

Not knowing your log message and what exactly being included in 4 of your inputting data set , I am not 100% sure about your problem, but my bet is that 'orderfact' does not have variable 'Country', instead, it has 'Customer_Country'. If that is the case, then it is an easy fix.

data billing (keep=Customer_ID Customer_Name Country Country_Name Product_ID Product_Name Order_Date Quantity Total_Retail_Price rename=country=Customer_Country);

  length Customer_ID 8. Order_Date 8. Product_ID 8. Quantity 8. Total_Retail_Price 8. Product_ID 8. Product_Name $50

         Customer_Country $5 Customer_Name $50 Country $5 Country_Name $25;

  if _N_=1 then do;

  declare hash P(dataset:'orion.product_list');

  P.definekey('Product_ID');

  P.definedata('Product_Name');

  P.definedone();

  declare hash D(dataset:'orion.customer_dim');

  D.definekey('Customer_ID');

  D.definedata('Customer_Country','Customer_Name');

  D.definedone();

  declare hash C(dataset:'orion.country');

  C.definekey('Country');

  C.definedata('Country_Name');

  C.definedone();

  call missing(Product_ID, Product_Name, Customer_ID, Customer_Name, Country, Country_Name);

  end;

  set orderfact (rename=Customer_Country=country);

rc1=P.find();

  rc2=D.find();

  rc3=C.find();

run;

BTW, key name does not need to be spelled out explicitly in find() method.

Good Luck,

Haikuo

InfoAlisaA
Calcite | Level 5

Thanks! This helped out a lot! Smiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1545 views
  • 0 likes
  • 2 in conversation