loops %do i = 1 %to ...

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

loops %do i = 1 %to ...

data flow;

infile cards dlm=','; * DLM ;

input  month1  month2 month3 month4 ;

cards;

45,0,1,2

100,10,0,100

10,90,1,20

; run;

Hi guys. I would like to create a loop that rename month1 as month6.

accordingly month2 will become month7, month3 will be month8 etc.

In real life I have 180 months so I really need a loop or macro.

I guess it should a sort of double loop, one referring to month1 to month180,

the other referring to month8 to month186 (the renamed months).

I could mana...ge a single loop %do i = 1 %to 180 but i can't figure out how to insert the second one

Any idea? thanks!


Accepted Solutions
Solution
‎02-07-2014 08:57 AM
Respected Advisor
Posts: 3,777

Re: loops %do i = 1 %to ...

You don't need a macro or loop just use RENAME data set option.  You just want to shift the enumeration right?

data flow(rename=(month1-month180=month6-month185));
   infile cards dsd missover;
  
input  month1-month180;
   cards;
45,0,1,2
100,10,0,100
10,90,1,20
;;;;
   run;

View solution in original post


All Replies
Solution
‎02-07-2014 08:57 AM
Respected Advisor
Posts: 3,777

Re: loops %do i = 1 %to ...

You don't need a macro or loop just use RENAME data set option.  You just want to shift the enumeration right?

data flow(rename=(month1-month180=month6-month185));
   infile cards dsd missover;
  
input  month1-month180;
   cards;
45,0,1,2
100,10,0,100
10,90,1,20
;;;;
   run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 186 views
  • 0 likes
  • 2 in conversation