I have a four-variable dataset. Sometimes, total_cost is repeated in a fiscal_year. I'd like to add all the costs by fiscal_year so there's only one row per org per year. Thank you!
data have;
length organization_name $10.;
input project_number organization_name fiscal_year total_cost;
cards;
1 orgA 2013 200
2 orgA 2014 300
3 orgA 2014 500
4 orgA 2014 200
5 orgB 2022 300
6 orgB 2022 400
7 orgB 2023 400
8 orgC 2012 200
9 orgC 2013 450
10 orgC 2013 1100
run;
These types of questions, where you want to calculate some statistic (in this case the sum) for different groups, is a job for PROC SUMMARY.
data have;
length organization_name $10.;
input project_number organization_name fiscal_year total_cost;
cards;
1 orgA 2013 200
2 orgA 2014 300
3 orgA 2014 500
4 orgA 2014 200
5 orgB 2022 300
6 orgB 2022 400
7 orgB 2023 400
8 orgC 2012 200
9 orgC 2013 450
10 orgC 2013 1100
;
proc summary data=have nway;
class organization_name fiscal_year;
var total_cost;
output out=want sum=;
run;
These types of questions, where you want to calculate some statistic (in this case the sum) for different groups, is a job for PROC SUMMARY.
data have;
length organization_name $10.;
input project_number organization_name fiscal_year total_cost;
cards;
1 orgA 2013 200
2 orgA 2014 300
3 orgA 2014 500
4 orgA 2014 200
5 orgB 2022 300
6 orgB 2022 400
7 orgB 2023 400
8 orgC 2012 200
9 orgC 2013 450
10 orgC 2013 1100
;
proc summary data=have nway;
class organization_name fiscal_year;
var total_cost;
output out=want sum=;
run;
Exactly what I needed- thank you!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: