Desktop productivity for business analysts and programmers

Data step to look at different values

Reply
Occasional Contributor
Posts: 16

Data step to look at different values

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.

Super User
Posts: 18,984

Re: Data step to look at different values

If you're in EG have you tried the summarize task?
Add customer/product to the Classification variables and amount to the analysis variable
Super User
Posts: 5,351

Re: Data step to look at different values

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.

Ask a Question
Discussion stats
  • 2 replies
  • 232 views
  • 0 likes
  • 3 in conversation