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

Hi SAS community,

 

I need help turning this logic into a program. I am trying to count the number of visits (with the variable Count) based on unique dates. This is what my data looks like.

 

Dataset

 

data dsn;
input PID $ Date  $ Place  Provider;
datalines;
001 10/10/2019 11 456
001 10/11/2019 11 400
001 10/11/2019 11 400
001 10/12/2019 11 509
;
run;

 

I would want an accumulating variable (Count) in my output like this;

PID Date Place Provider Count

001 10/10/2019 11 456 1

001 10/11/2019 11 400 2

001 10/11/2019 11 400 2

001 10/12/2019 11 509 3


Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data want;
set dsn;
by pid Date;
retain count;
if first.pid then count=1;
else if first.date then count+1;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

data want;
set dsn;
by pid Date;
retain count;
if first.pid then count=1;
else if first.date then count+1;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 586 views
  • 0 likes
  • 2 in conversation