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!
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.