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,

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

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

InfoAlisaA
Calcite | Level 5

Thank you! This helped a lot!:smileylaugh:

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
  • 1114 views
  • 0 likes
  • 2 in conversation