Sum of variable values in proc tabulate

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Sum of variable values in proc tabulate

HI all,

    How to find the sum of variables used proc tabulate.My table contain Relation as variable which holds mother,father,wife etc..

I need to get the total of mother and father in single observation.Any possible way to find the solution???

Krishnan


Accepted Solutions
Solution
‎09-03-2014 06:26 AM
Super User
Super User
Posts: 7,988

Re: Sum of variable values in proc tabulate

Posted in reply to KrishnaChandra

Depends what you want the output to look like.  If you want something like:

Mother/Father    XXX.X   XXX.X

Wife/Husband    XXX.X   XXX.X

Then pre-process you data to have that grouping:

data have;

     set original_data;

     length new_group $200;

     if relation in ("mother","father") then new_group="Mother/Father";

     else if relation in ("wife","husband") then new_group="Wife/Husband";

     else ...;

run;

proc tabulate...

     group new_group...

...;

You could maybe also do  it with formats, but really depends on your output requirements.

View solution in original post


All Replies
Solution
‎09-03-2014 06:26 AM
Super User
Super User
Posts: 7,988

Re: Sum of variable values in proc tabulate

Posted in reply to KrishnaChandra

Depends what you want the output to look like.  If you want something like:

Mother/Father    XXX.X   XXX.X

Wife/Husband    XXX.X   XXX.X

Then pre-process you data to have that grouping:

data have;

     set original_data;

     length new_group $200;

     if relation in ("mother","father") then new_group="Mother/Father";

     else if relation in ("wife","husband") then new_group="Wife/Husband";

     else ...;

run;

proc tabulate...

     group new_group...

...;

You could maybe also do  it with formats, but really depends on your output requirements.

Super User
Posts: 11,343

Re: Sum of variable values in proc tabulate

Posted in reply to KrishnaChandra

Give some examples of the data as your data structure is likely to affect the solution.

Trusted Advisor
Posts: 1,228

Re: Sum of variable values in proc tabulate

Posted in reply to KrishnaChandra

data have;
input relation $ amount;
datalines;
Mother 500
Father 500
Whife  200
Father 500
;

proc tabulate data=have(where=(relation='Mother' or relation='Father'));
class relation;
var amount;
table all='Mother/Father',amount;
run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 230 views
  • 0 likes
  • 4 in conversation