08-17-2016 02:46 AM
I want to collapse (group) my data by time (seconds). Sounds easy, well, but doesn't work.
I assume it is because CEIL does not round to integers but that's just a guess and I tried INT without success.
Why do I still get duplicate seconds observations? (The volume variable should be summed up when collapsing.)
So basically: I converted milliseconds to seconds and want to bring them to unique seconds observations. So, keep all observations, collapse seconds (which are duplicate) and sum up their values in the variable "volume".
data temp; set have; seconds = ceil(int(miliseconds/1000)); run; proc sql; create table want as select *, sum(volume) as SecVolume from temp group by seconds; quit;run; proc sort data=want; by id date seconds; run;
08-17-2016 02:57 AM - edited 08-18-2016 02:20 AM
Take a close look at the log of your SQL; you'll find a NOTE about remerging summary statistics.
If you include columns other than the summary values and the columns used in the group by, all observations will appear in the output, and the summary results will be merged back into all of them.
Your SQL should look rather like this:
proc sql; create table want as select id, date, seconds, sum(volume) as SecVolume from temp group by id, date, seconds; quit;run;
08-17-2016 10:38 AM
I obviously don't know where you are going with this but I would suggest creating a SAS time valued variable. Then you can use a FORMAT that only displays to whole seconds (if I understand what your attempt at rounding is doing) for most procedures.
data example; input time; datalines; 1.1 1.2 0.003 5.02 5.04 120.23 120.45 ; run; proc freq data=example; tables time; format time time8.; run;