Hello there,
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".
Any idea?
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;
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;
Works perfect, thanks again Kurt 🙂
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;
Thank you, solved it with proc sql but freq will also work!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.