Hello Everyone,
So I have the following table that I need to create a hash object from:
Continent ID | Continent Name | Location |
91 | North America | North |
93 | Europe | North |
94 | Africa | South |
95 | Asia | South |
96 | Australia/Pacific | South |
This is my code so far:
data _null_ (keep=Continent_ID Continent_Name Location);
length Continent_ID 3.;
length Continent_Name $25;
length Location $5;
if _N_=1 then do;
declare hash L();
L.definekey('Continent_ID');
L.definedata('Continent_Name','Location');
L.definedone();
L.add(key:96,data:'Australia/Pacific',data:'South');
L.add(key:95,data:'Asia',data:'South');
L.add(key:94,data:'Africa',data:'South');
L.add(key:93,data:'Europe',data:'North');
L.add(key:91,data:'North America',data:'North');
call missing(Continent_ID,Continent_Name,Location);
end;
L.output(dataset:'continents');
run;
proc print data=continents;
run;
The problem I am having right now is that I am not getting my Continent_ID to output with the rest of the hash object. I am able to get the Continent_Name and Location to print out, but I am not able to get the key to print out.
Could someone take a look at my code and let me know where I am going wrong?
Thanks,
Alisa
Alisa,
You only output every variable that you have defined as 'data', 'key' plays as an index, will not be part of your output data set if you skip it.
BTW, when doing 'data _null_', none of the data set options will make a difference, as you are NOT outputting anything anyway.
data _null_ /*(keep=Continent_ID Continent_Name Location)*/;
length Continent_ID 3.;
length Continent_Name $25;
length Location $5;
if _N_=1 then do;
declare hash L();
L.definekey('Continent_ID');
L.definedata('Continent_Id','Continent_Name','Location');
L.definedone();
L.add(key:96,data:96,data:'Australia/Pacific',data:'South');
L.add(key:95,data:95,data:'Asia',data:'South');
L.add(key:94,data:94,data:'Africa',data:'South');
L.add(key:93,data:93,data:'Europe',data:'North');
L.add(key:91,data:91,data:'North America',data:'North');
call missing(Continent_ID,Continent_Name,Location);
end;
L.output(dataset:'continents');
run;
proc print data=continents;
run;
Haikuo
Alisa,
You only output every variable that you have defined as 'data', 'key' plays as an index, will not be part of your output data set if you skip it.
BTW, when doing 'data _null_', none of the data set options will make a difference, as you are NOT outputting anything anyway.
data _null_ /*(keep=Continent_ID Continent_Name Location)*/;
length Continent_ID 3.;
length Continent_Name $25;
length Location $5;
if _N_=1 then do;
declare hash L();
L.definekey('Continent_ID');
L.definedata('Continent_Id','Continent_Name','Location');
L.definedone();
L.add(key:96,data:96,data:'Australia/Pacific',data:'South');
L.add(key:95,data:95,data:'Asia',data:'South');
L.add(key:94,data:94,data:'Africa',data:'South');
L.add(key:93,data:93,data:'Europe',data:'North');
L.add(key:91,data:91,data:'North America',data:'North');
call missing(Continent_ID,Continent_Name,Location);
end;
L.output(dataset:'continents');
run;
proc print data=continents;
run;
Haikuo
Thank you! This helped a lot!:smileylaugh:
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.