Help using Base SAS procedures

Multiple Hash Objects Code Check

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

Multiple Hash Objects Code Check

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(keySmiley Tongueroduct_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


Accepted Solutions
Solution
‎04-22-2012 01:32 PM
Respected Advisor
Posts: 3,124

Re: Multiple Hash Objects Code Check

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


All Replies
Solution
‎04-22-2012 01:32 PM
Respected Advisor
Posts: 3,124

Re: Multiple Hash Objects Code Check

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

Frequent Contributor
Posts: 90

Re: Multiple Hash Objects Code Check

Thanks! This helped out a lot! Smiley Happy

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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