BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sapt86
Fluorite | Level 6

I am trying to create a sequence number to enumerate the total number of visits to a service (I cannot delete duplicates because of other variables). 

I already have a variable that indicates if the client presented unique visits. Therefore, the sequence number should enumerate all visits but keep the same number when any client does not present a unique visit. 

 

I hope you can help me with this since I'm quite new in SAS. Thank you!!

 

IDUnique_visitTotal_visits (NEEDED)
111
112
102
213
214
315
305
316
417
418
408
419

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want;
 set have;
 Total_visits +unique_visit;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data want;
 set have;
 Total_visits +unique_visit;
run;
Sapt86
Fluorite | Level 6

I cannot believe that I was overthinking this. Thank you so much!!

Reeza
Super User
This requires a RETAIN, which tells SAS to keep the value to the next row. You can explicitly tell SAS to retain the variable but a SUM statement as in novinosrin will add an IMPLICIT retain that will keep the values across the rows. The first variable in the SUM statement is part of the implicit retain.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 2328 views
  • 2 likes
  • 3 in conversation