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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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