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:

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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