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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 336 views
  • 2 likes
  • 3 in conversation