Customer | Product | amount |
Paul | apple | 2 |
Paul | banana | 5 |
Paul | apple | 3 |
James | banana | 2 |
James | grape | 5 |
James | banana | 3 |
Here is the table I have.. I have tried to simplify the questions so you understand what i am doing. Trying to create a data step that sums up all the products of apple.. if apple is not in the list for paul then return the banana amount.
Here's one approach ... note that these are tools you will need to master in the long run.
proc summary data=have nway;
var amount;
class customer product;
where product in ('apple', 'banana');
output out=totals (keep=customer product amount) sum=;
run;
data want;
set totals;
by customer;
if last.customer;
run;
Note that the data set TOTALS will automatically be in order BY CUSTOMER PRODUCT. So if "banana" is there, it will be the last one for a CUSTOMER. If not, "apple" will be the last one.
Good luck.
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.