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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 862 views
  • 0 likes
  • 2 in conversation