I am working with time use data. 3 Days have been tracked. I'd like to get the total time spent on those three days on each activity.
my data looks something like this:
id| activity1 |activity5 |activity6 |activity761 |quarter
1 | 60 | 0 | 0 | 0 | 3 |
1 | 50 | 0 | 0 | 0 | 3 |
1 | 0 | 0 | 0 | 0 | 3 |
2 | 10 | 0 | 30 | 0 | 2 |
2 | 10 | 0 | 30 | 0 | 2 |
2 | 0 | 0 | 0 | 5 | 2 |
3 | 0 | 0 | 0 | 5 | 4 |
3 | 0 | 0 | 0 | 5 | 4 |
I'd like a result something like this:
id |activity1 |activity5| activity6 |activity761 |quarter
1 | 100 | 0 | 0 | 0 | 3 |
2 | 20 | 0 | 60 | 5 | 2 |
3 | 0 | 0 | 0 | 10 | 4 |
somewhere else on this board I found code working for my usecase, but it is very slow, also SAS Student edition warns me no to show the output.
proc means data = timeuse nway;
class id;
var activity1 activity5 activity6 activity761;
output out=timeuse_added sum =;
run;
Any suggestions on how to speed up this step? (to keep the quarters I managed to merge the old dataset by id)
How many observations do you have? Why do you need PROC MEANS to run faster, and what do you consider slow?
I made two changes to your code below. If you presort and switch to a BY instead of CLASS it may be faster if this isn’t fast enough.
@asdf0990 wrote:
I am working with time use data. 3 Days have been tracked. I'd like to get the total time spent on those three days on each activity.
my data looks something like this:
id| activity1 |activity5 |activity6 |activity761 |quarter
1 60 0 0 0 3 1
500 0 0 3 1 0 0 0 0 3 2 10 0 30 0 2 2 10 0 30 0 2 2 0 0 0 5 2 3 0 0 0 5 4 3 0 0 0 5 4
I'd like a result something like this:
id |activity1 |activity5| activity6 |activity761 |quarter
1 100 0 0 0 3 2 20 0 60 5 2 3 0 0 0 10 4
somewhere else on this board I found code working for my usecase, but it is very slow, also SAS Student edition warns me no to show the output.
proc means data = timeuse nway noprint; class id; var activity1 activity5 activity6 activity761; output out=timeuse_added sum = / auto name autolabel; run; out
Any suggestions on how to speed up this step? (to keep the quarters I managed to merge the old dataset by id)
@Reeza wrote:How many observations do you have? Why do you need PROC MEANS to run faster, and what do you consider slow?
I have 32105 rows and 705 variables in the dataset. I want to add up about 100 variable values. I consider 5 minutes for that step slow, given that I want to 20x the amount of calculations to be done.
thank you for the tips, I sorted allready, will look into the rest
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.