Help using Base SAS procedures

How to Divide two rows?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How to Divide two rows?

Here is my dataset. I want to calculate Percentage as Y/(Y+N) using Count number for both NBUS and Season. Anyone know how to get the results?  Thanks a lot

StatusTenureCount
NNBUS543
NSeason1099
YNBUS276
YSeason264

Accepted Solutions
Solution
‎03-08-2013 09:38 AM
Frequent Contributor
Frequent Contributor
Posts: 94

Re: How to Divide two rows?

proc sql;

     create table want1 as select

     status, tenure, count, sum(count) as sum

     from have

     group by tenure;

quit;

proc sql;

     create table want2 as select

     status, tenure, count/sum*100 as percent

      from want1

      where status='Y';

quit;

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: How to Divide two rows?

data have;

input Status $ Tenure $ Count;

cards;

N NBUS 543

N Season 1099

Y NBUS 276

Y Season 264

run;

proc sql;

create table want as

select status, tenure, count, count/sum(count) as Pct

from have;

quit;

Occasional Contributor
Posts: 6

Re: How to Divide two rows?

The Final result I want to get is 276/(276+543) for NBUS, 264/(264+1099) for Season.

Super Contributor
Posts: 578

Re: How to Divide two rows?

proc sql;

create table want as

select status, tenure, count, count/sum(count) as Pct

from have

group by tenure;

quit;

Solution
‎03-08-2013 09:38 AM
Frequent Contributor
Frequent Contributor
Posts: 94

Re: How to Divide two rows?

proc sql;

     create table want1 as select

     status, tenure, count, sum(count) as sum

     from have

     group by tenure;

quit;

proc sql;

     create table want2 as select

     status, tenure, count/sum*100 as percent

      from want1

      where status='Y';

quit;

Respected Advisor
Posts: 3,777

Re: How to Divide two rows?

Times 100.

title "276/(276+543)=%sysevalF(276/(276+543)) for NBUS, 264/(264+1099)=%sysevalF(264/(264+1099)) for Season";
proc freq data=have;
   tables status*tenure / norow nopercent;
  
weight count;
   run;
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 1299 views
  • 6 likes
  • 4 in conversation