DATA Step, Macro, Functions and more

Merging Sets... Can someone explain these results?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 130
Accepted Solution

Merging Sets... Can someone explain these results?

Hi,

 

I merged two sets by the variable model, and created a new variable called Newtotal. The bike model "Trek" works perfectly, but Canondale produces missing data, even though there is no missing data in either of the two sets. Can someone take a look and see what I am doing wrong? Thanks.

 

Here is the first set:

 

libname Learn '/folders/myfolders/Learn' ; 
data learn.bicycles;
   input Country  & $25.
         Model    & $14.
         Manuf    : $10.
         Units    :   5.
         UnitCost :  comma8.;
   TotalSales = (Units * UnitCost) / 1000;
   format UnitCost TotalSales dollar10.;
   label TotalSales = "Sales in Thousands"
         Manuf = "Manufacturer";
datalines;
USA  Road Bike  Trek 5000 $2,200
USA  Road Bike  Cannondale 2000 $2,100
USA  Mountain Bike  Trek 6000 $1,200
USA  Mountain Bike  Cannondale 4000 $2,700
USA  Hybrid  Trek 4500 $650
France  Road Bike  Trek 3400 $2,500
France  Road Bike  Cannondale 900 $3,700
France  Mountain Bike  Trek 5600 $1,300
France  Mountain Bike  Cannondale  800 $1,899
France  Hybrid  Trek 1100 $540
United Kingdom  Road Bike  Trek 2444 $2,100
United Kingdom  Road Bike  Cannondale  1200 $2,123
United Kingdom  Hybrid  Trek 800 $490
United Kingdom  Hybrid  Cannondale 500 $880
United Kingdom  Mountain Bike  Trek 1211 $1,121
Italy  Hybrid  Trek 700 $690
Italy  Road Bike  Trek 4500  $2,890
Italy  Mountain Bike  Trek 3400  $1,877
;

Second Set:

Data review.markup ; 
	input manuf : $10. markup ; 
Datalines ; 
Canondale 1.05 
Trek 1.07 
; 

My Code:

proc sort data=learn.bicycles ; 
	by Manuf ; 
run ; 

proc sort data=review.markup ; 
	by manuf ; 
run ; 

Data review.Markup_Price ; 
	Merge learn.bicycles review.markup  ; 
	by Manuf ;  
	NewTotal = Unitcost*Markup ;
run ;  

Proc print data=review.markup_price noobs ; 
	Var manuf unitcost markup Newtotal ; 
run ; 

Finally, the results:

Manuf 	UnitCost 	markup 	NewTotal
Cannondale 	$880 	. 	.
Cannondale 	$1,899 	. 	.
Cannondale 	$2,700 	. 	.
Cannondale 	$3,700 	. 	.
Cannondale 	$2,123 	. 	.
Cannondale 	$2,100 	. 	.
Canondale 	. 	1.05 	.
Trek 	$690 	1.07 	738.30
Trek 	$490 	1.07 	524.30
Trek 	$540 	1.07 	577.80
Trek 	$650 	1.07 	695.50
Trek 	$1,121 	1.07 	1199.47
Trek 	$1,877 	1.07 	2008.39
Trek 	$1,300 	1.07 	1391.00
Trek 	$1,200 	1.07 	1284.00
Trek 	$2,100 	1.07 	2247.00
Trek 	$2,500 	1.07 	2675.00
Trek 	$2,890 	1.07 	3092.30
Trek 	$2,200 	1.07 	2354.00

Accepted Solutions
Solution
‎04-25-2018 12:54 AM
Frequent Contributor
Posts: 130

Re: Merging Sets... Can someone explain these results?

Posted in reply to ManitobaMoose

I see. Cannondale was spelled Canondale in the second set. Everything works now. Thanks.

View solution in original post


All Replies
Frequent Contributor
Posts: 130

Re: Merging Sets... Can someone explain these results?

Posted in reply to ManitobaMoose

I'm sorry, the bike manuf is Trek and Canondale, not the Model. The code is written for this. Thanks.

Solution
‎04-25-2018 12:54 AM
Frequent Contributor
Posts: 130

Re: Merging Sets... Can someone explain these results?

Posted in reply to ManitobaMoose

I see. Cannondale was spelled Canondale in the second set. Everything works now. Thanks.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 118 views
  • 0 likes
  • 1 in conversation