BookmarkSubscribeRSS Feed
paul2877
Calcite | Level 5
CustomerProductamount
Paulapple2
Paulbanana5
Paulapple3
Jamesbanana2
Jamesgrape5
Jamesbanana3

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.

2 REPLIES 2
Reeza
Super User
If you're in EG have you tried the summarize task?
Add customer/product to the Classification variables and amount to the analysis variable
Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 726 views
  • 0 likes
  • 3 in conversation