DATA Step, Macro, Functions and more

skip the do loop in macro for one i value

Reply
Contributor
Posts: 68

skip the do loop in macro for one i value

Hello Expert,

 

I need a small Doubt, I am running a do macro loop for 72 columns, means 12 categories.

 

I have 6 columns which attribute name is repeating with increment numbers like below.

 

Base1,tax1,com1,int1,amt1,charges1,Base2,tax2,com2,int2,amt2,charges2,Base12,tax12,com12,int12,amt12,charges12.

 

I am generating only 3 column value (base,tax,int) in one column row wise.

 

%var1=base;

%var2=tax;

%var3=com;

%var4=int;

%var5=amt;

%var6=charges;

 

%do base=1 %to 12;

%do i=1 %to 4;

 

 

so I am generating a value in one column which will take data all 4 columns.

Now my question is to leave third column value only to take 1,2,4 value of i.

 

how can we can skip one value in do macro loop.

 

Please help  me.

 

Super User
Posts: 5,513

Re: skip the do loop in macro for one i value

[ Edited ]
Posted in reply to Ritesh_dellvostro

An easy patch:

 

%do base=1 %to 12;

%do i=1 %to 4;

%if &i ne 3 %then %do;

 

Macro language does not support iterating through a list of values, only iterating over a range.

 

Another possibility:

 

%if &i=3 %then %let i=4;

Super User
Super User
Posts: 7,976

Re: skip the do loop in macro for one i value

Posted in reply to Ritesh_dellvostro

And why the need for macro?  

data want;
  set have;
  array base_a{*} base:;
  array tax_a{*} tax:;
  ...
  do i=1 to dim(base_a);
    ...
  end;
run;

There are of course various other options as well.  Restructure the data for one:

ROW_ID  BASE  TAX  ...
1              xx        xx    ...
2              xx        xx    ...
etc.

Then yu just apply any calculations to base or tax on a row level rather than iterating across.  Simpler coding, and if you need a report at the end with it across the page, then do a transpose the data.

Ask a Question
Discussion stats
  • 2 replies
  • 113 views
  • 1 like
  • 3 in conversation