BookmarkSubscribeRSS Feed
Riteshdell
Quartz | Level 8

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.

 

2 REPLIES 2
Astounding
PROC Star

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;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1749 views
  • 1 like
  • 3 in conversation