## Calculating percentage

Solved
Occasional Contributor
Posts: 18

# 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???

 Country LandCost Vendor Customer Percentages New_Landcost France 575 Express 10 0.527272727 303.18 Japan 720 Express 10 0.527272727 379.64 Greece 698 Express 20 0.527272727 368.04 Italy 468 Express 9 0.527272727 246.76 Ireland 558 Express 9 0.527272727 294.22 Spain 510 World 12 0.472727273 241.09 Brazil 540 World 6 0.472727273 255.27 Venezuela 425 World 8 0.472727273 200.91 Russia 924 World 6 0.472727273 436.80 Switzerland 734 World 20 0.472727273 346.98

 This is how the percentage was arrived at Vendor Customer Percentages Express 58 0.52727 World 52 0.47273 Total 110 1

Accepted Solutions
Solution
‎06-18-2013 06:21 AM
Super User
Posts: 10,784

## Re: Calculating percentage

Posted in reply to sasthebest
```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

All Replies
Solution
‎06-18-2013 06:21 AM
Super User
Posts: 10,784

## Re: Calculating percentage

Posted in reply to sasthebest
```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

Posted in reply to sasthebest

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 and locked.

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

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