Hellow SAS members,
I have a data set with some variables I want to aggregate (workout_mins...) by summarizing them and some variables I want to keep the same (age, sex...). How can I do that?
My data is listed like this:
ID Date Workout_mins Age Sex Drink
1 1 20 36 1 0
1 2 15 36 1 1
1 3 0 36 1 0
1 4 0 36 1 1
1 5 95 36 1 1
1 6 60 36 1 1
1 7 60 36 1 0
2 1 0 25 0 0
2 2 10 25 0 0
....
group by id,age,sex
data have;
input ID Date Workout_mins Age Sex Drink ;
cards;
1 1 20 36 1 0
1 2 15 36 1 1
1 3 0 36 1 0
1 4 0 36 1 1
1 5 95 36 1 1
1 6 60 36 1 1
1 7 60 36 1 0
2 1 0 25 0 0
2 2 10 25 0 0
;
proc sql;
create table want as
select id,age,sex,sum(workout_mins) as workout_mins_sum
from have
group by id,age,sex;
quit;
What summarization?
by summarizing them
and expected output?
Hi novinosrin,
I want to sum workout_mins while keeping other variables such as age, sex same. The expected out is like this:
ID workout_mins_sum age sex
...
group by id,age,sex
data have;
input ID Date Workout_mins Age Sex Drink ;
cards;
1 1 20 36 1 0
1 2 15 36 1 1
1 3 0 36 1 0
1 4 0 36 1 1
1 5 95 36 1 1
1 6 60 36 1 1
1 7 60 36 1 0
2 1 0 25 0 0
2 2 10 25 0 0
;
proc sql;
create table want as
select id,age,sex,sum(workout_mins) as workout_mins_sum
from have
group by id,age,sex;
quit;
so does Date which may or may not be a real date has no impact on you summary
and does drink have anything to do in the summary?
If the clients age changes does your summary line change do we keep summing based on ID?
Date has a value fixed like that (probably date order). Drink is a dummy variable if the person drinks on specific day, but I am not sure how to use it in my analysis now 😞 Right now I think age of clients stays the same
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.