I have one table having one column Primary Coverage (having 2 observation, but in future their is possible to have more than2 observation)
I want to create a macro to loop through Year, Quarter, month and Column value dynamically, so that my table should look like this: (2000Q1 to 2001Q1= 15 month, 5 Quarters, and 1 Year) (Please answer...its really urgent)
year | quarter | Primary_coverage | months |
2000 | 1 | combined single limit | 3 |
2000 | 1 | combined single limit | 6 |
2000 | 1 | combined single limit | 9 |
2000 | 1 | combined single limit | 12 |
2000 | 1 | combined single limit | 15 |
2000 | 2 | combined single limit | 3 |
2000 | 2 | combined single limit | 6 |
2000 | 2 | combined single limit | 9 |
2000 | 2 | combined single limit | 12 |
2000 | 2 | combined single limit | 15 |
2000 | 3 | combined single limit | 3 |
2000 | 3 | combined single limit | 6 |
2000 | 3 | combined single limit | 9 |
2000 | 3 | combined single limit | 12 |
2000 | 3 | combined single limit | 15 |
2000 | 4 | combined single limit | 3 |
2000 | 4 | combined single limit | 6 |
2000 | 4 | combined single limit | 9 |
2000 | 4 | combined single limit | 12 |
2000 | 4 | combined single limit | 15 |
2001 | 1 | combined single limit | 3 |
2001 | 1 | combined single limit | 6 |
2001 | 1 | combined single limit | 9 |
2001 | 1 | combined single limit | 12 |
2001 | 1 | combined single limit | 15 |
2000 | 1 | uninsured motorist | 3 |
2000 | 1 | uninsured motorist | 6 |
2000 | 1 | uninsured motorist | 9 |
2000 | 1 | uninsured motorist | 12 |
2000 | 1 | uninsured motorist | 15 |
2000 | 2 | uninsured motorist | 3 |
2000 | 2 | uninsured motorist | 6 |
2000 | 2 | uninsured motorist | 9 |
2000 | 2 | uninsured motorist | 12 |
2000 | 2 | uninsured motorist | 15 |
2000 | 3 | uninsured motorist | 3 |
2000 | 3 | uninsured motorist | 6 |
2000 | 3 | uninsured motorist | 9 |
2000 | 3 | uninsured motorist | 12 |
2000 | 3 | uninsured motorist | 15 |
2000 | 4 | uninsured motorist | 3 |
2000 | 4 | uninsured motorist | 6 |
2000 | 4 | uninsured motorist | 9 |
2000 | 4 | uninsured motorist | 12 |
2000 | 4 | uninsured motorist | 15 |
2001 | 1 | uninsured motorist | 3 |
2001 | 1 | uninsured motorist | 6 |
2001 | 1 | uninsured motorist | 9 |
2001 | 1 | uninsured motorist | 12 |
2001 | 1 | uninsured motorist | 15 |
But when i run the same program on 2001Q3 , then my table data should look like this ( 2000Q1 to 2001Q3= 21 month, 7 Quarters and 1 Year) (Please find attached file for same )
year | quarter | Primary_coverage | months |
2000 | 1 | combined single limit | 3 |
2000 | 1 | combined single limit | 6 |
2000 | 1 | combined single limit | 9 |
2000 | 1 | combined single limit | 12 |
2000 | 1 | combined single limit | 15 |
2000 | 1 | combined single limit | 18 |
2000 | 1 | combined single limit | 21 |
2000 | 2 | combined single limit | 3 |
2000 | 2 | combined single limit | 6 |
2000 | 2 | combined single limit | 9 |
2000 | 2 | combined single limit | 12 |
2000 | 2 | combined single limit | 15 |
2000 | 2 | combined single limit | 18 |
2000 | 2 | combined single limit | 21 |
2000 | 3 | combined single limit | 3 |
2000 | 3 | combined single limit | 6 |
2000 | 3 | combined single limit | 9 |
2000 | 3 | combined single limit | 12 |
2000 | 3 | combined single limit | 15 |
2000 | 3 | combined single limit | 18 |
2000 | 3 | combined single limit | 21 |
2000 | 4 | combined single limit | 3 |
2000 | 4 | combined single limit | 6 |
2000 | 4 | combined single limit | 9 |
2000 | 4 | combined single limit | 12 |
2000 | 4 | combined single limit | 15 |
2000 | 4 | combined single limit | 18 |
2000 | 4 | combined single limit | 21 |
2001 | 1 | combined single limit | 3 |
2001 | 1 | combined single limit | 6 |
2001 | 1 | combined single limit | 9 |
2001 | 1 | combined single limit | 12 |
2001 | 1 | combined single limit | 15 |
2001 | 1 | combined single limit | 18 |
2001 | 1 | combined single limit | 21 |
2001 | 2 | combined single limit | 3 |
2001 | 2 | combined single limit | 6 |
2001 | 2 | combined single limit | 9 |
2001 | 2 | combined single limit | 12 |
2001 | 2 | combined single limit | 15 |
2001 | 2 | combined single limit | 18 |
2001 | 2 | combined single limit | 21 |
2001 | 3 | combined single limit | 3 |
2001 | 3 | combined single limit | 6 |
2001 | 3 | combined single limit | 9 |
2001 | 3 | combined single limit | 12 |
2001 | 3 | combined single limit | 15 |
2001 | 3 | combined single limit | 18 |
2001 | 3 | combined single limit | 21 |
2000 | 1 | uninsured motorist | 3 |
2000 | 1 | uninsured motorist | 6 |
2000 | 1 | uninsured motorist | 9 |
2000 | 1 | uninsured motorist | 12 |
2000 | 1 | uninsured motorist | 15 |
2000 | 1 | uninsured motorist | 18 |
2000 | 1 | uninsured motorist | 21 |
2000 | 2 | uninsured motorist | 3 |
2000 | 2 | uninsured motorist | 6 |
2000 | 2 | uninsured motorist | 9 |
2000 | 2 | uninsured motorist | 12 |
2000 | 2 | uninsured motorist | 15 |
2000 | 2 | uninsured motorist | 18 |
2000 | 2 | uninsured motorist | 21 |
2000 | 3 | uninsured motorist | 3 |
2000 | 3 | uninsured motorist | 6 |
2000 | 3 | uninsured motorist | 9 |
2000 | 3 | uninsured motorist | 12 |
2000 | 3 | uninsured motorist | 15 |
2000 | 3 | uninsured motorist | 18 |
2000 | 3 | uninsured motorist | 21 |
2000 | 4 | uninsured motorist | 3 |
2000 | 4 | uninsured motorist | 6 |
2000 | 4 | uninsured motorist | 9 |
2000 | 4 | uninsured motorist | 12 |
2000 | 4 | uninsured motorist | 15 |
2000 | 4 | uninsured motorist | 18 |
2000 | 4 | uninsured motorist | 21 |
2001 | 1 | uninsured motorist | 3 |
2001 | 1 | uninsured motorist | 6 |
2001 | 1 | uninsured motorist | 9 |
2001 | 1 | uninsured motorist | 12 |
2001 | 1 | uninsured motorist | 15 |
2001 | 1 | uninsured motorist | 18 |
2001 | 1 | uninsured motorist | 21 |
2001 | 2 | uninsured motorist | 3 |
2001 | 2 | uninsured motorist | 6 |
2001 | 2 | uninsured motorist | 9 |
2001 | 2 | uninsured motorist | 12 |
2001 | 2 | uninsured motorist | 15 |
2001 | 2 | uninsured motorist | 18 |
2001 | 2 | uninsured motorist | 21 |
2001 | 3 | uninsured motorist | 3 |
2001 | 3 | uninsured motorist | 6 |
2001 | 3 | uninsured motorist | 9 |
2001 | 3 | uninsured motorist | 12 |
2001 | 3 | uninsured motorist | 15 |
2001 | 3 | uninsured motorist | 18 |
2001 | 3 | uninsured motorist | 21 |
You had a post about this earlier on where solutions were provided. Please don't post test data in the form of Excel files, these are dangerous and should not be downloaded. Post test data - just a few observations, in the format of a datastep, so that we can run it and see what your data looks like. Secondly there is no need for macros here, you can use a datastep with a simple do loop to achieve your goal:
data want; do year=<start value> to <your_value>; do quarter=<start value> to <your_quarter>; <create a record>; output; end; end; run;
To get code closer to your data, post your data as a datastep.
@subrat1 wrote:
I want to create a macro to loop through Year, Quarter, month and Column value dynamically, so that my table should look like this: (2000Q1 to 2001Q1= 15 month, 5 Quarters, and 1 Year) (Please answer...its really urgent)
I posted a solution in your other thread, did you try that, it works perfectly for me.
If it doesn't please explain why. I'm not prepared to spend any more time on this problem if you won't take the time to explain your issue and continue to spam your question everywhere. I also answered your question on SO.
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.