Calculating percentage

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Calculating percentage

data tourrevenue;

    input Country $ 1-11 LandCost Vendor $ customer;

cards;

France       575 Express  10

Spain        510 World    12

Brazil       540 World     6

Japan        720 Express  10

Greece       698 Express  20

Venezuela    425 World     8

Italy        468 Express   9

Russia       924 World     6

Switzerland  734 World    20

Ireland      558 Express   9

;

Run;

Proc sort data = tourrevenue

by vendor;

run;

How do I get to this from the data set about???

CountryLandCostVendorCustomerPercentagesNew_Landcost
France575Express100.527272727                 303.18
Japan720Express100.527272727                 379.64
Greece698Express200.527272727                 368.04
Italy468Express90.527272727                 246.76
Ireland558Express90.527272727                 294.22
Spain510World120.472727273                 241.09
Brazil540World60.472727273                 255.27
Venezuela425World80.472727273                 200.91
Russia924World60.472727273                 436.80
Switzerland734World200.472727273                 346.98

This is how the percentage was arrived at
VendorCustomerPercentages
Express580.52727
World520.47273
Total1101

Accepted Solutions
Solution
‎06-18-2013 06:21 AM
Super User
Posts: 9,662

Re: Calculating percentage

data have;
    input Country $ 1-11 LandCost Vendor $ customer;
cards;
France       575 Express  10
Spain        510 World    12
Brazil       540 World     6
Japan        720 Express  10
Greece       698 Express  20
Venezuela    425 World     8
Italy        468 Express   9
Russia       924 World     6
Switzerland  734 World    20
Ireland      558 Express   9
;
Run;
Proc sort data = have;
by vendor;
run;
proc sql;
create table want as
 select *,(select sum(customer) from have where Vendor=a.Vendor)/(select  sum(customer) from have) as per format=8.5,calculated per*landcost as new
  from have as a;
quit;

Ksharp

View solution in original post


All Replies
Solution
‎06-18-2013 06:21 AM
Super User
Posts: 9,662

Re: Calculating percentage

data have;
    input Country $ 1-11 LandCost Vendor $ customer;
cards;
France       575 Express  10
Spain        510 World    12
Brazil       540 World     6
Japan        720 Express  10
Greece       698 Express  20
Venezuela    425 World     8
Italy        468 Express   9
Russia       924 World     6
Switzerland  734 World    20
Ireland      558 Express   9
;
Run;
Proc sort data = have;
by vendor;
run;
proc sql;
create table want as
 select *,(select sum(customer) from have where Vendor=a.Vendor)/(select  sum(customer) from have) as per format=8.5,calculated per*landcost as new
  from have as a;
quit;

Ksharp

Contributor
Posts: 29

Re: Calculating percentage

Try below code : Will get the same result as required.

data
tourrevenue;

input Country :$ 1-11 LandCost Vendor $ customer;

cards;

  France       575 Express  10

  Spain        510 World    12

  Brazil       540 World     6

  Japan        720 Express  10

  Greece       698 Express  20

  Venezuela    425 World     8

  Italy        468 Express   9

  Russia       924 World     6

  Switzerland  734 World   20

  Ireland      558 Express   9

  ;  Run;

Proc sort data = tourrevenue ;by vendor; run;

data Percen;

input Vendor $ Customer Percentages;

cards;

Express 58 0.52727

World 52 0.47273

; run;

proc sort data = percen; by vendor; run;

data merge_both;  

merge  tourrevenue(in=aa) percen(In=bb);

by Vendor;

if aa = 1;

New_Landcost =  LandCost*Percentages;  run;

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 196 views
  • 1 like
  • 3 in conversation