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
Simple application of BY group processing.
data want;
set have;
by well_group;
count+1;
if first.well_group then count=1;
run;
Simple application of BY group processing.
data want;
set have;
by well_group;
count+1;
if first.well_group then count=1;
run;
This outlines how you can do this:
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
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!
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.