BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasthebest
Calcite | Level 5

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
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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

2 REPLIES 2
Ksharp
Super User
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

sunilzood
Calcite | Level 5

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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