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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 15 replies
  • 5270 views
  • 2 likes
  • 7 in conversation