turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- how to calculate sum and replace it in missing val...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-20-2017 05:08 AM

I have a dataset as below

PT N

102 25

103 34

Total .

I need to replace the missing with the sum of the 2 counts in N. Can i do that in datastep?

Accepted Solutions

Solution

10-20-2017
05:39 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-20-2017 05:24 AM

You can retain a variable where you sum up all N values, and when PT = 'Total', you set N to that value.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

All Replies

Solution

10-20-2017
05:39 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-20-2017 05:24 AM

You can retain a variable where you sum up all N values, and when PT = 'Total', you set N to that value.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-20-2017 05:31 AM

Whilst @KurtBremser has given you the answer, I would step back one and ask why you have a dataset which looks like that in the first place. How have you added "Total" without adding the sum in at the same time, seems like the step before needs changing. You can add totals on in various ways, my first thought was:

proc sql; create table WANT as select * from HAVE union all select "Total", sum(N) from HAVE; quit;

Simply adds a row at the end of the dataset with total.