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!

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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