I have the following code and table I'm using. I am trying to do two different things.
1. Pull back just the rows with the most recent date per product. IE there would be three rows, one for each fruit, and the most recent date per fruit.
2. Do the same thing as 1, except I want to add code that allows for a prompt where I will enter a certain date and just pull back the most recent record per fruit less than or equal to the date I entered.
PROC SQL;
CREATE TABLE WORK.Most_Recent_Price_Per_Fruit AS
SELECT
Product,
Date,
Price
FROM Database.FruitTable
AND Price NOT= 0
ORDER BY Product, Date
;
QUIT;
Date
Product
Price
01Jan2019
Oranges
$1.00
01Jun2020
Oranges
$1.75
01Mar2023
Oranges
$1.50
01Sep2021
Apples
$1.00
01Mar2023
Apples
$2.00
01Jan2019
Bananas
$5.00
01Jun2020
Bananas
$3.00
Results from option 1 in blue (rest would not be pulled back just included for reference)
Date
Product
Price
01Jan2019
Oranges
$1.00
01Jun2020
Oranges
$1.75
01Mar2023
Oranges
$1.50
01Sep2021
Apples
$1.00
01Mar2023
Apples
$2.00
01Jan2019
Bananas
$5.00
01Jun2020
Bananas
$3.00
Results from option 2 in blue assuming entering prompt date of 01MAY2022 (rest would not be pulled back just included for reference)
Date
Product
Price
01Jan2019
Oranges
$1.00
01Jun2020
Oranges
$1.75
01Mar2023
Oranges
$1.50
01Sep2021
Apples
$1.00
01Mar2023
Apples
$2.00
01Jan2019
Bananas
$5.00
01Jun2020
Bananas
$3.00
... View more