Christopher Knapp University of Akron, Fall 2011 Statistical Data Management Homework #10 Problem Statement This assignment contains sample data from Northwind Traders, Inc., a mythical firm that sells exotic beverages and confections. In this assignment, you will use PROC SQL to build queries using the Northwind Traders data. The following pictures shows how the data tables are related. Please go to the document “Northwind Database Description” on Springboard for a complete explanation of the data tables and data columns. Load the data for each of the tables into SAS. Be sure to use the appropriate formats for each variable. These tables are also located on the “R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx.” Please note that each table resides in a separate tab in this Excel spreadsheet. Build queries, and submit any output using PROC SQL to answer the following questions: Write a query that displays an alphabetical list (first and last name only) of all Northwind Traders employees. Write a query that displays an alphabetical list of all Northwind Traders employees that are not sales representatives. Include the employees title in this report. Write a query that displays the names of all Northwind Traders customers who are based in Brazil. Include customer id, name, city, and country, sorted by name. What were the total number of orders placed by order date? How many total orders were placed in the first quarter of 1995 (Jan, Feb, and Mar)? Your answer should include a single number that is based on the order date. How many orders were sent to each customer? How many orders has each employee written? Your results should sort by employee last name. How many units are in stock for each product in inventory? Create a report sorted by product name. What was the total units sold and total sales before a discount (Unit Price * Quantity) for products that have been discontinued? Create a report sorted by product name. How many orders by day were shipped for the shipping company United Package in 1994. Show a report that includes Company Name, Shipped Date, and numbers of orders by ship date for this company. For Graduates Students: For each customer, how many UNIQUE orders were placed, what was the total sales before a discount (Unit Price * Quantity), total discounts given to each customer, and total sales after the discount. o Hint: must use a special count function that only counts distinct order ids. Contents Data Import Page 1 Code Queries Page 2 Query 1 Page 3 Query 2 Page 4 Query 3 Page 5 Query 4 Page 6 Query 5 Page 7 Query 6 Page 8 Query 7 Page 9 Query 8 Page 10 Query 9 Page 11 Query 10 Page 12 Query 11 Appendix Appendix A Full output for Query 4 Appendix B Full SAS Code Assignment 10 Page |1 Data Import libname mylib '\\uanet.edu\ZIPSpace\C\crk32\Classes\F11 Statistical Data Management\Assignment 10\mylib'; PROC IMPORT OUT= mylib.OrderDetails DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="'Order Details$'"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Customers DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Customers$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Employees DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Employees$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Orders DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Orders$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Products DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Products$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Shippers DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Shippers$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; Assignment 10 Page |2 Query 1 Instruction: Write a query that displays an alphabetical list (first and last name only) of all Northwind Traders employees Result of Query: Code: /* QUERY 1 */ PROC SQL; SELECT Lastname, Firstname FROM Mylib.Employees ORDER BY Lastname; SELECT Firstname, Lastname FROM Mylib.Employees ORDER BY Firstname; QUIT; Assignment 10 Page |3 Query 2 Instruction: Write a query that displays an alphabetical list of all Northwind Traders employees that are not sales representatives. Include the employees title in this report. Result of Query: Code: /* QUERY 2 */ PROC SQL; SELECT Lastname, Firstname, Title FROM Mylib.Employees WHERE Title<>'Sales Representative' ORDER BY Lastname; QUIT; Assignment 10 Page |4 Query 3 Instruction: Write a query that displays the names of all Northwind Traders customers who are based in Brazil. Include customer id, name, city, and country, sorted by name Result of Query: Code: /* QUERY 3 */ PROC SQL; SELECT CustomerID, CompanyName, City, Country FROM Mylib.Customers WHERE Country='Brazil' ORDER BY CompanyName; QUIT; Assignment 10 Page |5 Query 4 Instruction: What were the total number of orders placed by order date? Partial Result of Query: **Note that the full output can be found in Appendix A Code: /* QUERY 4 */ PROC SQL; SELECT OrderDate, COUNT(OrderID) AS numOfOrders FROM Mylib.Orders GROUP BY OrderDate; QUIT; Assignment 10 Page |6 Query 5 Instruction: How many total orders were placed in the first quarter of 1995 (Jan, Feb, and Mar)? Your answer should include a single number that is based on the order date. Result of Query: Code: /* QUERY 5 */ PROC SQL; SELECT count(orderid) AS NumOfOrders FROM Mylib.Orders WHERE OrderDate >= '01JAN1995'd AND OrderDate < '01APR1995'd; QUIT; Assignment 10 Page |7 Query 6 Instruction: How many orders were sent to each customer? Result of Query: Code: /* QUERY 6 */ PROC SQL; SELECT CustomerID, Count(OrderID) AS NumOfOrders FROM Mylib.Orders GROUP BY CustomerID; QUIT; Assignment 10 Page |8 Query 7 Instruction: How many orders has each employee written? Your results should sort by employee last name. Result of Query: Code: /* QUERY 7 */ PROC SQL; SELECT A.LastName, A.FirstName, count(B.OrderID) AS NumOfOrders FROM Mylib.Employees A, Mylib.Orders B WHERE A.EmployeeID = B.EmployeeID GROUP BY A.LastName , A.FirstName ORDER BY A.LastName; QUIT; Assignment 10 Page |9 Query 8 Instruction: How many units are in stock for each product in inventory? Create a report sorted by product name. Result of Query: Code: /* QUERY 8 */ PROC SQL; SELECT ProductName, UnitsInStock FROM Mylib.Products ORDER BY ProductName; QUIT; Assignment 10 P a g e | 10 Query 9 Instruction: What was the total units sold and total sales before a discount (Unit Price * Quantity) for products that have been discontinued? Create a report sorted by product name. Result of Query: Code: /* QUERY 9 */ PROC SQL; SELECT B.ProductName, SUM(A.Quantity) AS TotalQuantity, SUM(A.Quantity*A.UnitPrice) AS TotalSales FROM Mylib.Orderdetails A, Mylib.Products B WHERE (A.ProductID = B.ProductID) AND B.Discontinued='Yes' GROUP BY B.ProductName; QUIT; Assignment 10 P a g e | 11 Query 10 Instruction: How many orders by day were shipped for the shipping company United Package in 1994. Show a report that includes Company Name, Shipped Date, and numbers of orders by ship date for this company. Result of Query: Code: /* QUERY 10 */ PROC SQL; SELECT DISTINCT A.shippeddate, Count(A.OrderID) AS NumOfOrders, B.CompanyName FROM Mylib.Orders A, Mylib.Shippers B WHERE A.ShipVia = 2 AND A.shippedDate>='01JAN1994'd AND A.shippedDate<'01JAN1995'd AND A.ShipVia = B.ShipperID GROUP BY A.ShippedDate ORDER BY A.ShippedDate; QUIT; Assignment 10 P a g e | 12 Query 11 Instruction: For each customer, how many UNIQUE orders were placed, what was the total sales before a discount (Unit Price * Quantity), total discounts given to each customer, and total sales after the discount. Result of Query: Code: /* QUERY 11 */ PROC SQL; SELECT A.CompanyName AS Company, Count( distinct B.OrderID) AS OrdersPlaced, sum(C.UnitPrice * C.Quantity) AS SalesBeforeDiscount, sum(C.Discount*C.UnitPrice*C.Quantity) AS TotalDiscount, sum((1-C.Discount)*C.UnitPrice*C.Quantity) AS SalesAfterDiscount FROM Mylib.Customers A, Mylib.Orders B, Mylib.OrderDetails C WHERE A.CustomerID=B.CustomerID AND B.OrderID=C.OrderID GROUP BY A.CompanyName; QUIT; Assignment 10 Appendix A |1 Full Output for Query 4 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 04AUG1994 1 05AUG1994 1 08AUG1994 2 09AUG1994 1 10AUG1994 1 11AUG1994 1 12AUG1994 1 15AUG1994 1 16AUG1994 1 17AUG1994 1 18AUG1994 1 19AUG1994 2 22AUG1994 1 23AUG1994 1 24AUG1994 1 25AUG1994 1 26AUG1994 1 29AUG1994 1 30AUG1994 1 31AUG1994 1 01SEP1994 2 02SEP1994 1 05SEP1994 1 06SEP1994 1 07SEP1994 1 08SEP1994 1 09SEP1994 1 12SEP1994 1 13SEP1994 1 14SEP1994 2 15SEP1994 1 16SEP1994 1 19SEP1994 1 20SEP1994 1 21SEP1994 1 22SEP1994 1 23SEP1994 1 26SEP1994 1 27SEP1994 2 28SEP1994 1 Assignment 10 Appendix A |2 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 29SEP1994 1 30SEP1994 1 03OCT1994 1 04OCT1994 1 05OCT1994 1 06OCT1994 1 07OCT1994 1 10OCT1994 2 11OCT1994 1 12OCT1994 1 13OCT1994 1 14OCT1994 1 17OCT1994 1 18OCT1994 1 19OCT1994 1 20OCT1994 1 21OCT1994 2 24OCT1994 1 25OCT1994 1 26OCT1994 1 27OCT1994 1 28OCT1994 1 31OCT1994 1 01NOV1994 1 02NOV1994 1 03NOV1994 2 04NOV1994 1 07NOV1994 1 08NOV1994 1 09NOV1994 1 10NOV1994 1 11NOV1994 1 14NOV1994 1 15NOV1994 1 16NOV1994 2 17NOV1994 1 18NOV1994 1 21NOV1994 1 22NOV1994 1 23NOV1994 1 92 Assignment 10 Appendix A |3 The SAS System OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 24NOV1994 1 25NOV1994 1 28NOV1994 1 29NOV1994 2 30NOV1994 1 01DEC1994 1 02DEC1994 1 05DEC1994 1 06DEC1994 1 07DEC1994 1 08DEC1994 1 09DEC1994 1 12DEC1994 2 13DEC1994 1 14DEC1994 1 15DEC1994 1 16DEC1994 1 19DEC1994 1 20DEC1994 1 21DEC1994 1 22DEC1994 1 23DEC1994 2 26DEC1994 1 27DEC1994 2 28DEC1994 1 29DEC1994 2 30DEC1994 1 02JAN1995 1 03JAN1995 2 04JAN1995 1 05JAN1995 2 06JAN1995 1 09JAN1995 2 10JAN1995 1 11JAN1995 1 12JAN1995 2 13JAN1995 1 16JAN1995 2 17JAN1995 1 18JAN1995 2 18:43 Sunday, October 30, 2011 93 Assignment 10 Appendix A |4 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 19JAN1995 1 20JAN1995 1 23JAN1995 2 24JAN1995 1 25JAN1995 2 26JAN1995 1 27JAN1995 2 30JAN1995 1 31JAN1995 1 01FEB1995 2 02FEB1995 1 03FEB1995 2 06FEB1995 1 07FEB1995 2 08FEB1995 1 09FEB1995 1 10FEB1995 2 13FEB1995 1 14FEB1995 2 15FEB1995 1 16FEB1995 2 17FEB1995 1 20FEB1995 1 21FEB1995 2 22FEB1995 1 23FEB1995 2 24FEB1995 1 27FEB1995 2 28FEB1995 1 01MAR1995 1 02MAR1995 2 03MAR1995 1 06MAR1995 2 07MAR1995 1 08MAR1995 2 09MAR1995 1 10MAR1995 1 13MAR1995 2 14MAR1995 1 15MAR1995 2 94 Assignment 10 Appendix A |5 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 16MAR1995 1 17MAR1995 2 20MAR1995 1 21MAR1995 1 22MAR1995 2 23MAR1995 1 24MAR1995 2 27MAR1995 1 28MAR1995 2 29MAR1995 1 30MAR1995 1 31MAR1995 2 03APR1995 1 04APR1995 2 05APR1995 1 06APR1995 2 07APR1995 1 10APR1995 1 11APR1995 2 12APR1995 1 13APR1995 2 14APR1995 1 17APR1995 2 18APR1995 1 19APR1995 1 20APR1995 2 21APR1995 1 24APR1995 2 25APR1995 1 26APR1995 2 27APR1995 1 28APR1995 1 01MAY1995 2 02MAY1995 1 03MAY1995 2 04MAY1995 1 05MAY1995 2 08MAY1995 1 09MAY1995 1 10MAY1995 2 95 Assignment 10 Appendix A |6 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 11MAY1995 1 12MAY1995 2 15MAY1995 1 16MAY1995 2 17MAY1995 1 18MAY1995 1 19MAY1995 2 22MAY1995 1 23MAY1995 2 24MAY1995 1 25MAY1995 2 26MAY1995 1 29MAY1995 1 30MAY1995 2 31MAY1995 1 01JUN1995 2 02JUN1995 1 05JUN1995 2 06JUN1995 1 07JUN1995 1 08JUN1995 2 09JUN1995 1 12JUN1995 2 13JUN1995 1 14JUN1995 2 15JUN1995 1 16JUN1995 1 19JUN1995 2 20JUN1995 1 21JUN1995 2 22JUN1995 1 23JUN1995 2 26JUN1995 1 27JUN1995 1 28JUN1995 2 29JUN1995 1 30JUN1995 2 03JUL1995 1 04JUL1995 2 05JUL1995 1 96 Assignment 10 Appendix A |7 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 06JUL1995 1 07JUL1995 2 10JUL1995 1 11JUL1995 2 12JUL1995 1 13JUL1995 2 14JUL1995 1 17JUL1995 1 18JUL1995 2 19JUL1995 1 20JUL1995 2 21JUL1995 1 24JUL1995 2 25JUL1995 1 26JUL1995 1 27JUL1995 2 28JUL1995 1 31JUL1995 2 01AUG1995 1 02AUG1995 2 03AUG1995 1 04AUG1995 1 07AUG1995 2 08AUG1995 1 09AUG1995 2 10AUG1995 1 11AUG1995 2 14AUG1995 1 15AUG1995 1 16AUG1995 2 17AUG1995 1 18AUG1995 2 21AUG1995 1 22AUG1995 2 23AUG1995 1 24AUG1995 1 25AUG1995 2 28AUG1995 1 29AUG1995 2 30AUG1995 1 97 Assignment 10 Appendix A |8 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 31AUG1995 2 01SEP1995 1 04SEP1995 1 05SEP1995 2 06SEP1995 1 07SEP1995 2 08SEP1995 1 11SEP1995 2 12SEP1995 2 13SEP1995 1 14SEP1995 2 15SEP1995 2 18SEP1995 1 19SEP1995 2 20SEP1995 2 21SEP1995 1 22SEP1995 2 25SEP1995 2 26SEP1995 1 27SEP1995 2 28SEP1995 2 29SEP1995 1 02OCT1995 2 03OCT1995 2 04OCT1995 1 05OCT1995 2 06OCT1995 2 09OCT1995 1 10OCT1995 2 11OCT1995 2 12OCT1995 1 13OCT1995 2 16OCT1995 2 17OCT1995 1 18OCT1995 2 19OCT1995 2 20OCT1995 1 23OCT1995 2 24OCT1995 2 25OCT1995 1 98 Assignment 10 Appendix A |9 The SAS System 18:43 Sunday, October 30, 2011 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 26OCT1995 2 27OCT1995 2 30OCT1995 1 31OCT1995 2 01NOV1995 2 02NOV1995 1 03NOV1995 2 06NOV1995 2 07NOV1995 1 08NOV1995 2 09NOV1995 2 10NOV1995 1 13NOV1995 2 14NOV1995 2 15NOV1995 1 16NOV1995 2 17NOV1995 2 20NOV1995 1 21NOV1995 2 22NOV1995 2 23NOV1995 1 24NOV1995 2 27NOV1995 2 28NOV1995 1 29NOV1995 2 30NOV1995 2 01DEC1995 1 04DEC1995 2 05DEC1995 2 06DEC1995 1 07DEC1995 2 08DEC1995 2 11DEC1995 1 12DEC1995 2 13DEC1995 2 14DEC1995 1 15DEC1995 2 18DEC1995 2 19DEC1995 1 20DEC1995 2 99 Assignment 10 A p p e n d i x A | 10 The SAS System 18:43 Sunday, October 30, 2011 100 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 21DEC1995 2 22DEC1995 1 25DEC1995 2 26DEC1995 2 27DEC1995 1 28DEC1995 2 29DEC1995 2 01JAN1996 1 02JAN1996 2 03JAN1996 2 04JAN1996 1 05JAN1996 2 08JAN1996 2 09JAN1996 1 10JAN1996 2 11JAN1996 2 12JAN1996 1 15JAN1996 2 16JAN1996 3 17JAN1996 2 18JAN1996 3 19JAN1996 2 22JAN1996 3 23JAN1996 2 24JAN1996 3 25JAN1996 2 26JAN1996 3 29JAN1996 2 30JAN1996 3 31JAN1996 2 01FEB1996 3 02FEB1996 2 05FEB1996 3 06FEB1996 2 07FEB1996 3 08FEB1996 2 09FEB1996 3 12FEB1996 2 13FEB1996 3 14FEB1996 2 Assignment 10 A p p e n d i x A | 11 The SAS System 18:43 Sunday, October 30, 2011 101 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 15FEB1996 3 16FEB1996 2 19FEB1996 3 20FEB1996 2 21FEB1996 3 22FEB1996 2 23FEB1996 3 26FEB1996 2 27FEB1996 3 28FEB1996 2 29FEB1996 3 01MAR1996 2 04MAR1996 3 05MAR1996 2 06MAR1996 3 07MAR1996 2 08MAR1996 3 11MAR1996 2 12MAR1996 3 13MAR1996 2 14MAR1996 3 15MAR1996 2 18MAR1996 3 19MAR1996 2 20MAR1996 3 21MAR1996 2 22MAR1996 3 25MAR1996 2 26MAR1996 3 27MAR1996 2 28MAR1996 6 29MAR1996 3 01APR1996 3 02APR1996 4 03APR1996 3 04APR1996 3 05APR1996 4 08APR1996 3 09APR1996 3 10APR1996 4 Assignment 10 A p p e n d i x A | 12 The SAS System 18:43 Sunday, October 30, 2011 102 OrderDate numOfOrders ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 11APR1996 3 12APR1996 3 15APR1996 4 16APR1996 3 17APR1996 3 18APR1996 4 19APR1996 3 22APR1996 3 23APR1996 4 24APR1996 3 25APR1996 3 26APR1996 4 29APR1996 3 30APR1996 3 01MAY1996 4 02MAY1996 3 03MAY1996 3 06MAY1996 4 07MAY1996 3 08MAY1996 3 09MAY1996 4 10MAY1996 3 13MAY1996 3 14MAY1996 4 15MAY1996 3 16MAY1996 3 17MAY1996 4 20MAY1996 3 21MAY1996 3 22MAY1996 4 23MAY1996 3 24MAY1996 3 27MAY1996 4 28MAY1996 3 29MAY1996 3 30MAY1996 4 31MAY1996 3 03JUN1996 3 04JUN1996 4 05JUN1996 4 Assignment 10 Appendix B |1 Full SAS Code libname mylib '\\uanet.edu\ZIPSpace\C\crk32\Classes\F11 Statistical Data Management\Assignment 10\mylib'; PROC IMPORT OUT= mylib.OrderDetails DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="'Order Details$'"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Customers DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Customers$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Employees DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Employees$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Orders DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Orders$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Products DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Products$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; Assignment 10 Appendix B |2 USEDATE=YES; SCANTIME=YES; RUN; PROC IMPORT OUT= mylib.Shippers DATAFILE= "R:\Fridline\Statistical Data Management\Assignment #10\Northwind Traders Database.xlsx" DBMS=EXCEL REPLACE; RANGE="Shippers$"; GETNAMES=YES; MIXED=YES; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; /* QUERY 1 */ PROC SQL; SELECT Lastname, Firstname FROM Mylib.Employees ORDER BY Lastname; SELECT Firstname, Lastname FROM Mylib.Employees ORDER BY Firstname; QUIT; /* QUERY 2 */ PROC SQL; SELECT Lastname, Firstname, Title FROM Mylib.Employees WHERE Title<>'Sales Representative' ORDER BY Lastname; QUIT; /* QUERY 3 */ PROC SQL; SELECT CustomerID, CompanyName, City, Country FROM Mylib.Customers WHERE Country='Brazil' ORDER BY CompanyName; QUIT; /* QUERY 4 */ PROC SQL; SELECT OrderDate format date9., COUNT(OrderID) AS numOfOrders FROM Mylib.Orders GROUP BY OrderDate; QUIT; /* QUERY 5 */ PROC SQL; SELECT count(orderid) AS NumOfOrders FROM Mylib.Orders WHERE OrderDate >= '01JAN1995'd AND OrderDate < '01APR1995'd; QUIT; /* QUERY 6 */ PROC SQL; Assignment 10 Appendix B |3 SELECT CustomerID, Count(OrderID) AS NumOfOrders FROM Mylib.Orders GROUP BY CustomerID; QUIT; /* QUERY 7 */ PROC SQL; SELECT A.LastName, A.FirstName, count(B.OrderID) AS NumOfOrders FROM Mylib.Employees A, Mylib.Orders B WHERE A.EmployeeID = B.EmployeeID GROUP BY A.LastName , A.FirstName ORDER BY A.LastName; QUIT; /* QUERY 8 */ PROC SQL; SELECT ProductName, UnitsInStock FROM Mylib.Products ORDER BY ProductName; QUIT; /* QUERY 9 */ PROC SQL; SELECT B.ProductName, SUM(A.Quantity) AS TotalQuantity, SUM(A.Quantity*A.UnitPrice) AS TotalSales FROM Mylib.Orderdetails A, Mylib.Products B WHERE (A.ProductID = B.ProductID) AND B.Discontinued='Yes' GROUP BY B.ProductName; QUIT; /* QUERY 10 */ PROC SQL; SELECT DISTINCT A.shippeddate, Count(A.OrderID) AS NumOfOrders, B.CompanyName FROM Mylib.Orders A, Mylib.Shippers B WHERE A.ShipVia = 2 AND A.shippedDate>='01JAN1994'd AND A.shippedDate<'01JAN1995'd AND A.ShipVia = B.ShipperID GROUP BY A.ShippedDate ORDER BY A.ShippedDate; QUIT; /* QUERY 11 */ PROC SQL; SELECT A.CompanyName AS Company, Count( distinct B.OrderID) AS OrdersPlaced, sum(C.UnitPrice * C.Quantity) AS SalesBeforeDiscount, sum(C.Discount*C.UnitPrice*C.Quantity) AS TotalDiscount, sum((1-C.Discount)*C.UnitPrice*C.Quantity) AS SalesAfterDiscount FROM Mylib.Customers A, Mylib.Orders B, Mylib.OrderDetails C WHERE A.CustomerID=B.CustomerID AND B.OrderID=C.OrderID GROUP BY A.CompanyName; QUIT;