BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
fa04
Fluorite | Level 6

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
fa04
Fluorite | Level 6

Exactly what I needed- thank you!

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 481 views
  • 0 likes
  • 2 in conversation