BookmarkSubscribeRSS Feed
don_dadda
Fluorite | Level 6

I have three tables, columns in brackets:
Orders (product_id quantity)
Products (product_id name)
Stock (product_id uk us eu amea)

 

These have been imported into SAS Studio and I now need to create a VIEW called ‘top_three’ that shows the stock levels for the top
three selling products (by volume, not value). The VIEW should contain the following
fields:

  • name (from the product table)
  • A field totalling the volume of sales called ‘number_of_sales’
  • The four stock level fields: eu, us, uk and amea

(b) alter the script to add a field to the view for 1. (a) that shows the total sales as a
percentage of total stock. Call this field ‘sale_stock_percentage’

this is the code I have so far:

create view top_three_stock as
select a.name,
b.quantity,
c.uk,
c.eu,
c.us,
c.amea
from work.product a
full join work.stock c
on a.product_id = c.product_id
full join work.orders b
on a.product_id = b.product_id
;
5 REPLIES 5
PaigeMiller
Diamond | Level 26

Explain what formula would be used for SALE_STOCK_PERCENTAGE. Show us what you have tried for SALE_STOCK_PERCENTAGE.

--
Paige Miller
don_dadda
Fluorite | Level 6

Hi, I would need to find the total of all quantity and divide this by the total of all the 4 stock columns to get the percentage

PaigeMiller
Diamond | Level 26

Show us what you have tried for SALE_STOCK_PERCENTAGE.

--
Paige Miller
don_dadda
Fluorite | Level 6

I havent tried anything as of yet, here is where I have got to:

create table join1 as
select a.name, 
b.quantity,
c.uk, 
c.eu, 
c.us, 
c.amea
from work.product a
full join work.stock c
on a.product_id = c.product_id
full join work.order_product b
on a.product_id = b.product_id
;

create table sort1 as
select distinct name, sum(quantity) as number_of_sales, uk, us, eu, amea
from join1
group by name
order by number_of_sales desc
;

proc sql outlobs=3;
create view top_three as
select name, number_of_sales
from sort1;

my last piece isnt working as I would expect, it is listing all rows rather than just the top 3.

 

I do not know how to alter the view.

PaigeMiller
Diamond | Level 26
proc sql outlobs=3;

Your log should show an error on this command. That's what you need to fix.

--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 896 views
  • 0 likes
  • 2 in conversation