DATA Step, Macro, Functions and more

Loop Through Year , Quarter, Month, Column Value Dynamically, I need a macro

Reply
Contributor
Posts: 48

Loop Through Year , Quarter, Month, Column Value Dynamically, I need a macro

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)

yearquarterPrimary_coveragemonths
20001combined single limit3
20001combined single limit6
20001combined single limit9
20001combined single limit12
20001combined single limit15
20002combined single limit3
20002combined single limit6
20002combined single limit9
20002combined single limit12
20002combined single limit15
20003combined single limit3
20003combined single limit6
20003combined single limit9
20003combined single limit12
20003combined single limit15
20004combined single limit3
20004combined single limit6
20004combined single limit9
20004combined single limit12
20004combined single limit15
20011combined single limit3
20011combined single limit6
20011combined single limit9
20011combined single limit12
20011combined single limit15
20001uninsured motorist3
20001uninsured motorist6
20001uninsured motorist9
20001uninsured motorist12
20001uninsured motorist15
20002uninsured motorist3
20002uninsured motorist6
20002uninsured motorist9
20002uninsured motorist12
20002uninsured motorist15
20003uninsured motorist3
20003uninsured motorist6
20003uninsured motorist9
20003uninsured motorist12
20003uninsured motorist15
20004uninsured motorist3
20004uninsured motorist6
20004uninsured motorist9
20004uninsured motorist12
20004uninsured motorist15
20011uninsured motorist3
20011uninsured motorist6
20011uninsured motorist9
20011uninsured motorist12
20011uninsured motorist15

 

 

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 )

yearquarterPrimary_coveragemonths
20001combined single limit3
20001combined single limit6
20001combined single limit9
20001combined single limit12
20001combined single limit15
20001combined single limit18
20001combined single limit21
20002combined single limit3
20002combined single limit6
20002combined single limit9
20002combined single limit12
20002combined single limit15
20002combined single limit18
20002combined single limit21
20003combined single limit3
20003combined single limit6
20003combined single limit9
20003combined single limit12
20003combined single limit15
20003combined single limit18
20003combined single limit21
20004combined single limit3
20004combined single limit6
20004combined single limit9
20004combined single limit12
20004combined single limit15
20004combined single limit18
20004combined single limit21
20011combined single limit3
20011combined single limit6
20011combined single limit9
20011combined single limit12
20011combined single limit15
20011combined single limit18
20011combined single limit21
20012combined single limit3
20012combined single limit6
20012combined single limit9
20012combined single limit12
20012combined single limit15
20012combined single limit18
20012combined single limit21
20013combined single limit3
20013combined single limit6
20013combined single limit9
20013combined single limit12
20013combined single limit15
20013combined single limit18
20013combined single limit21
20001uninsured motorist3
20001uninsured motorist6
20001uninsured motorist9
20001uninsured motorist12
20001uninsured motorist15
20001uninsured motorist18
20001uninsured motorist21
20002uninsured motorist3
20002uninsured motorist6
20002uninsured motorist9
20002uninsured motorist12
20002uninsured motorist15
20002uninsured motorist18
20002uninsured motorist21
20003uninsured motorist3
20003uninsured motorist6
20003uninsured motorist9
20003uninsured motorist12
20003uninsured motorist15
20003uninsured motorist18
20003uninsured motorist21
20004uninsured motorist3
20004uninsured motorist6
20004uninsured motorist9
20004uninsured motorist12
20004uninsured motorist15
20004uninsured motorist18
20004uninsured motorist21
20011uninsured motorist3
20011uninsured motorist6
20011uninsured motorist9
20011uninsured motorist12
20011uninsured motorist15
20011uninsured motorist18
20011uninsured motorist21
20012uninsured motorist3
20012uninsured motorist6
20012uninsured motorist9
20012uninsured motorist12
20012uninsured motorist15
20012uninsured motorist18
20012uninsured motorist21
20013uninsured motorist3
20013uninsured motorist6
20013uninsured motorist9
20013uninsured motorist12
20013uninsured motorist15
20013uninsured motorist18
20013uninsured motorist21

 

 

 

 

Super User
Super User
Posts: 7,988

Re: Loop Through Year , Quarter, Month, Column Value Dynamically, I need a macro

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.

Super User
Posts: 19,860

Re: Loop Through Year , Quarter, Month, Column Value Dynamically, I need a macro


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.

Ask a Question
Discussion stats
  • 2 replies
  • 343 views
  • 0 likes
  • 3 in conversation