BookmarkSubscribeRSS Feed
data_null__
Jade | Level 19

The sascommunity tip of the day is hash sort.

http://www.sascommunity.org/wiki/Tip_of_the_Day:October_8

I thought it might be mildly interesting to generalize it and show an example of CALL VNEXT, my second favorite call routine.:smileysilly:

Not rigorously test your mileage may vary.

%let data=sashelp.class;
%let by=age sex;
%let keep=;
%let out=class;
data _null_;
  
if 0 then do;
     
set &data(keep=&keep);
      by &by;
      end;
  
declare hash srt(dataset:"&data",ordered:'Y',multidata:'Y');
   length _NAME_ $32;
  
do _n_ = 1 by 1;
     
call vnext(_name_);
      if missing(_name_) then leave;
      if _name_ eq '_NAME_' then leave;
      if _name_ eq: 'LAST.' then continue;
      put (_n_ _name_)(=);
      if _name_ ne: 'FIRST.' then srt.definedata(_name_);
      if _name_ eq: 'FIRST.' then srt.definekey(scan(_name_,-1,'.'));
     
end;
   srt.definedone();
   srt.output(dataset:
"&out");
  
stop;
  
run;
5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

what is your first favorite call routine?

data_null__
Jade | Level 19

CALL MISSING of course. :smileylaugh:

art297
Opal | Level 21

DN: Do we get a step-by-step explanation so we can discover why it is your second favorite?

Tom
Super User Tom
Super User

Is there something in there that I am missing that will make sure to sort by AGE SEX instead of by SEX AGE ?

data_null__
Jade | Level 19

The first variables are in the PDV in the same order as in the BY statement, because there was no prior reference to mess that up.  But we usually refer to LAST. before the SET and BY as in DO UNTIL(LAST....);  Not a problem here.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 1075 views
  • 1 like
  • 4 in conversation