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
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
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
Thanks! This helped out a lot!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.