BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mkt_apprentice
Obsidian | Level 7

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

....

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

What summarization?

 by summarizing them

 

and expected output?

mkt_apprentice
Obsidian | Level 7

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

...

novinosrin
Tourmaline | Level 20

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;
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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?

mkt_apprentice
Obsidian | Level 7

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 755 views
  • 0 likes
  • 3 in conversation