I have a large data set that I'd like to calculate number of "feeding events" by day for 120 individuals across 90 days.
There are anywhere from 90-200 feeding events per day.
Is there a way for SAS to "count" the number of times the EID shows up within the same date
Example:
1 | 840003208080904 | 08/22/2019 | 40 |
2 | 840003208080904 | 08/22/2019 | 30 |
3 | 840003208080904 | 08/22/2019 | 20 |
4 | 840003208080904 | 08/22/2019 | 120 |
5 | 840003208080905 | 08/22/2019 | 90 |
6 | 840003208080905 | 08/22/2019 | 90 |
7 | 840003208080905 | 08/22/2019 | 30 |
8 | 840003208080906 | 08/22/2019 | 0 |
9 | 840003208080906 | 08/22/2019 | 20 |
10 | 840003208080906 | 08/22/2019 | 40 |
Count often brings proc Freq into play.
proc freq data=have; tables eid * time /list; run;
is one way. If you want a data set you can add an out=datasetname to the option list after the / .
Several other procedures would work as well.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.