BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shawn123
Obsidian | Level 7

Hello guys. I have two questions regarding my code. The first one is the descending order inside the declare hash statement, which value will be applied to the descending order? I read material online, some people said the order would be applied on all the keys, so in my case, will the order only applied to the "score" variable? 

Another question is my code output nothing on the ge90 dataset. But I don't understand the reason? Thanks in advance!

data class_scores;
 input name :$9. score @@;
datalines;
Callum 82 Chyou 92
Damien 89 Grace 74
Jorge 99 Kyle 85
Lachlan 83 Lucia 90
Mia 91 Niamh 80
Philipp 89 Tomas 76
;
data top_quarter bottom_quarter ge90;
 length name $9 score 8;
 keep name score;
 if _n_=1 then do;
 declare hash h(dataset: 'class_scores', ordered: 'descending');
 h.defineKey('score');
 h.defineData('score','name');
 h.defineDone();
 call missing(name, score); 
 declare hiter hi('h');
 end;

 count=h.num_items;
 n=4;
 put count=;
 hi.first();
 do i=1 to n;
 output top_quarter;
 hi.next();
 end;
 hi.last();
 do i=1 to n;
 output bottom_quarter;
 hi.prev();
 end;
rc=hi.first();
do while(rc=0);
if socre>90 then output ge90;
rc=hi.next();
end;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
KachiM
Rhodochrosite | Level 12

Hi @shawn123 

 

The item included in KEY part is used for Sorting. Score is your Key. Therefore you are right.

The second is due to spelling error in 

socre

Correct it and you will get what you want. 

View solution in original post

2 REPLIES 2
KachiM
Rhodochrosite | Level 12

Hi @shawn123 

 

The item included in KEY part is used for Sorting. Score is your Key. Therefore you are right.

The second is due to spelling error in 

socre

Correct it and you will get what you want. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 668 views
  • 1 like
  • 2 in conversation