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

Dear programmers,

 

How can I count a fixed variable in an easy way?

 

What I have is:

 

 

WELL_NAME
A
A
A
A
A
A
A
A
A
B
B
C
C
C
C
C
C
C
C
D
D
E
E
E
E
E
E
F
F
F
F
F
F
F
F

 

What I want is:

 

WELL_NAME COUNT
A 1
A 2
A 3
A 4
A 5
A 6
A 7
A 8
A 9
B 1
B 2
C 1
C 2
C 3
C 4
C 5
C 6
C 7
C 8
D 1
D 2
E 1
E 2
E 3
E 4
E 5
E 6
F 1
F 2
F 3
F 4
F 5
F 6
F 7
F 8

 

Best regards

 

Farshid 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Simple application of BY group processing.

data want;
  set have;
  by well_group;
  count+1;
  if first.well_group then count=1;
run;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Simple application of BY group processing.

data want;
  set have;
  by well_group;
  count+1;
  if first.well_group then count=1;
run;
farshidowrang
Quartz | Level 8
Thank you very much my friend!

Best regards

Farshid
farshidowrang
Quartz | Level 8
Thank you!

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