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

 

Hi,

 

I simply would like to set a new Var "Counter" thats count to 12 (in the example below to 3) by the ID. I mean within the same ID, it can be hundred of them, I would like to count the rows by 12 (equivalent to months), each time gets to 12 then reset to 1 again until 12, to the end of the rows until ID changes. So this counter repeat itself in the same way for each new ID.

I imagine is simply, my problem is I am only learning!!! Thank you a lot for your help. Bernardita

 

IDCounter
A1
A2
A3
A1
A2
A3
A1
A2
A3
A1
B1
B2
B3
B1
B2
B3
B1
B2
B3
B1
B2
C1
C2
C3
C1
C2
C3
C1
C2
C3
C1
C2
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Yep, pretty simple - I will  go by your given example below:

data want;
  set have;
  by id;
  retain counter;
  if first.id or counter > 3 then counter=0;
  else counter=counter+1;
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Yep, pretty simple - I will  go by your given example below:

data want;
  set have;
  by id;
  retain counter;
  if first.id or counter > 3 then counter=0;
  else counter=counter+1;
run;
Bernardita
Fluorite | Level 6

This is great!!! Thank you a lot!

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