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

I am trying to use a do loop to number each individual issue date by account number in my data set.  Here is my data set:

 

AccountNumber     IssueDate      IssueNumber

        1001                1/1/2020               

        1001                2/1/2020               

        1001                3/1/2020               

        1001                4/1/2020               

        1002                1/2/2020               

        1002                1/15/2020             

        1003                1/5/2020               

        1003                1/20/2020             

        1003                1/31/2020             

 

I want to populate the IssueNumber field with the iterative do loop to number each entry for every individual AccountNumber as you see in .  The AccountNumber could have 1, 2, 5, 10, up to 52.

 

    DATA Records;

    SET Master;
DO i = 1 to 52; /*value range - could be less according to count of issuedate field*/
    DO IssueNumber = 1 to i;
        output;
            END;
    END;
RUN;

This is how I want to see from the output data set. 

 

AccountNumber     IssueDate      IssueNumber

        1001                1/1/2020               1

        1001                2/1/2020               2

        1001                3/1/2020               3

        1001                4/1/2020               4

        1002                1/2/2020               1

        1002                1/15/2020             2

        1003                1/5/2020               1

        1003                1/20/2020             2

        1003                1/31/2020             3

 

 

 

The code I have provided above is not providing the output I need for analysis.  Any feedback would be greatly appreciated.  Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

Use BY group processing and automatic variable FIRST.<byvar> to reset the counter at the start of each group.

 

Example:

data want;
  set have;
  by AccountNumber;
  if first.AccountNumber
then IssueNumber = 1;
else IssueNumber + 1; /* sum statement */ run;

View solution in original post

2 REPLIES 2
RichardDeVen
Barite | Level 11

Use BY group processing and automatic variable FIRST.<byvar> to reset the counter at the start of each group.

 

Example:

data want;
  set have;
  by AccountNumber;
  if first.AccountNumber
then IssueNumber = 1;
else IssueNumber + 1; /* sum statement */ run;
greg6363
Obsidian | Level 7
It worked. Thanks so much. Appreciate it.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 641 views
  • 2 likes
  • 2 in conversation