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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1143 views
  • 1 like
  • 3 in conversation