You undersold yourself on SAS skills! Had you supplied your code in the first post we could have given you more specific advice. I would recommend you do not sort your data, because it is already in date time order and a very large dataset consumes mega resources in sorting. Also, unless you are careful, the sort may disturb the existing order. To get distinct values of spot, and subsequently split your data Proc SQL Noprint ; Crate table spot_list as Select distinct spot from test2 ; Select distinct spot into :spotlist separated by ' ' /* space */ from spot_list ; Select count * into :spotcount from spot_list ; Quit ; %Let spottables = %sysfunc (translate(&spotlist, _, / )) ; %macro Whenspots ; %do i = 1 to &spotcount ; When "%Scan(&Spotlist, &i)" then output %Scan(&spottables, &i) ; %end ; %mend ; Data &spottables ; Set test2 ; time5min = int(timesec/300) ; /* calculate row average - not sure i understand your requirements fully here */ ... Format time5min time. ; Select spot ; %Whenspots ; Otherwise ; End ; Run ; From there you can modify my SQL code to get averages across 5 min intervals. Another SQL step (or Proc Summary with a class statement) can count your As, Bs, etc, and sum volumes, using "group by time5min, type" then followed by Proc transpose to put all the counts/sums into the same row. A datastep using first.time5min and last.time5min (times need not be on the exact boundary) can be used for calculations specific to those rows (if required.) Here is an outline fo at least soe of what you want %Macro AnalyseSpottbl (Spottbl) ; Proc SQL ; Create table &Spottbl._summary as Select date , spot , time5min , type , 'count_' || type as countname , 'bidvol_' || type as bidname , 'askvol_' || type as askname , count (*) as count5min , sum (bidvol) as bidvol5min , sum (askvol) as askvol5min from test2 group by 1, 2, 3, 4, 5, 6, 7 ; Quit ; Proc transpose data = &Spottbl._summary (rename = (bidname = _name_)) out = &Spottbl._bidvol (drop = _name_) ; By date spot time5min ; var bidvol5min ; Run ; Proc transpose data = &Spottbl._summary (rename = (askname = _name_)) out = &Spottbl._askvol (drop = _name_) ; By date spot time5min ; var askvol5min ; Run ; Proc transpose data = &Spottbl._summary (rename = (countname = _name_)) out = &Spottbl._counts (drop = _name_) ; By date spot time5min ; var count5min ; Run ; Data &Spottbl._allstats ; Merge &Spottbl._counts &Spottbl._bidvol &Spottbl._askvol ; By date spot time5min ; Run ; %Mend ; %Macro DoAnalysis (num) ; %Do I = 1 to &num ; %Let Spottbl = %Scan(&spottables, &i) ; %AnalyseSpottbl (&Spottbl) ; %End ; %Mend ; %DoAnalysis (&spotcount) ; Good luck Richard
... View more