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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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