BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ksharp
Super User

Hi , Patrick and PGStat.

I figure out another Hash solution without pre-sorting dataset .I think it will be faster than your SQL.

Just Guess. Smiley Happy

proc import datafile='d:\software\SampleFile.xls' out=have dbms=excel replace;
getnames=yes;run;
data have(drop=_f);
 set have(rename=(filldat=_f));
 filldat=input(_f,mmddyy10.);
 format filldat mmddyy10.;
run;

proc sql noprint;
 select quote(name) into : list separated by ','
  from dictionary.columns
   where libname='WORK' and memname='HAVE';
quit; 
data _null_;
if _n_ eq 1 then do;
declare hash ha1();
declare hiter hi1('ha1');
declare hash ha2();
 ha1.definekey('_year','_qtr');
 ha1.definedata('_year','_qtr','ha2');
 ha1.definedone();
end;
 set have end=last;
 _year=year(filldat);_qtr=qtr(filldat);
 if ha1.find()=0 then ha2.add();
  else do;
        ha2=_new_ hash(multidata:'Y');
        ha2.definekey('_year','_qtr');
        ha2.definedata(&list);
        ha2.definedone();
        ha2.add();
        ha1.add();
      end;
 if last then do;
                do while(hi1.next()=0);
                  ha2.output(dataset: cats('Q',_qtr,'_',_year));
                end;
              end;
run;



Ksharp

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 8155 views
  • 2 likes
  • 7 in conversation