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.
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;
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.