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.
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;
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;
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.
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.
Ready to level-up your skills? Choose your own adventure.