BookmarkSubscribeRSS Feed
lsehlola
Calcite | Level 5

Hi

I am trying to to increment the product field by 1 for each occurrence of account number. i.e account number 1 has three records where the product 1 and 2 are populated.  want to look at the last value for the the product number and add one to it.

 

please see example below:

 

AccountProduct 
11
12
1 
21
22
23
2 
31
32
33
34
3 
3 
3 

  expected outcome:

 

AccountProduct 
11
12
13
21
22
23
24
31
32
33
34
3

5

36
37
1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
infile datalines missover;
input Account Product;
datalines;
1 1
1 2
1  
2 1
2 2
2 3
2  
3 1
3 2
3 3
3 4
3  
3  
3  
;

data want(drop = p);
   set have;
   if Product then p = Product;
   else do;
      p = sum(p, 1);
      Product = p;
   end;
   retain p;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 844 views
  • 0 likes
  • 2 in conversation