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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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