BookmarkSubscribeRSS Feed
XiaoyanZhao
Calcite | Level 5

Hi, Dear all

Please rescue me! I have a urgent request but don't know what to do with it.

I am running a macro 60 times, then put data into one table. I was thinking to use do loop to let it run 60 times and proc append them into 1 file. After searching for 1 hour, I am here. Can anyone kindly help me?

Many thanks

Hi, all I end up add a macro as below for running macro analysis 30 times to boostrap. Thank you all

%Macro doit;

%do i =1 %to 30;

%if i > 30 %then %do;

%analysis('01jan14'd,'31jan14'd, '01-01-2014','01-31-2014')

%end;

%end;

%mend;

11 REPLIES 11
LinusH
Tourmaline | Level 20

Not knowing what is behind the requirement is sounds like you are on the right track (depending on what your macro does).

Data never sleeps
art297
Opal | Level 21

I think you're on the right track, but you might want to include the proc append within the macro. That way you don't have to keep track of file names and might be able to reuse the same filename for all of the individual files your macro creates.

XiaoyanZhao
Calcite | Level 5

My macro would generate a table with 2 columns, one is from Jan, 2014 to Dec 2014 (once per month) as Time, one is the number that I wanted. But the result is ramdom. So I want to run it 60 times and ave the number that I wanted. Don't know how to write the execute macro 60 times in do loop code. Help me please........ Smiley Sad

Thanks

Hi, all

I end up add the macro in the code to execute macro analysis 30 time to bootstrap data for random selected results.

%Macro doit;

%do i =1 %to 30;

%if i > 30 %then %do;

%analysis('01jan14'd,'31jan14'd, '01-01-2014','01-31-2014')

%end;

%end;

%mend;

%DOIT

Reeza
Super User

Post a sample macro call, preferably a few. Or even your macro code.

You can generally use call execute within a a data step loop.

XiaoyanZhao
Calcite | Level 5

Hi, all

I end up add the macro in the code to execute macro analysis 30 time to bootstrap data for random selected results.

%Macro doit;

%do i =1 %to 30;

%if i > 30 %then %do;

%analysis('01jan14'd,'31jan14'd, '01-01-2014','01-31-2014')

%end;

%end;

%mend;

%DOIT

Reeza
Super User

You don't use i in the %analysis call, so it executes the same thing over and over...

art297
Opal | Level 21

plus the only reason it does anything is because the letter i has a greater value than the characters '30'.

If you are trying to base a decision of whether of not to do something based on the value of &i, you have to specify &i in your %do statement.  i.e., %if &i. gt 30 %then %do

However, in this case, you wouldn't do anything since &i will only be greater than 30 as it leaves the loop.

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

Suggest starting with available SAS.COM support / communities resources - Internet search might include argument:

macro do loop generate code site:sas.com

As has been suggested, post what doesn't work.

Also, consider SAS OPTIONS such as NODSNFERR NOVNFERR NOBYERR, if you intend to code one set / logic-path, otherwise look at using macro language logic involving %SYSFUNC(EXIST(<member_name>))  to control initial code-path.

XiaoyanZhao
Calcite | Level 5

Hi, all Thanks for your helps. I end up adding a do loop as  below to run the macro 30 times to bootstrap random data.

%Macro doit;

%do i =1 %to 30;

%if i > 30 %then %do;

%analysis('01jan14'd,'31jan14'd, '01-01-2014','01-31-2014')

%end;

%end;

%mend;

XiaoyanZhao
Calcite | Level 5

Hi, all Smiley Happy

I end up add the macro in the code to execute macro analysis 30 time to bootstrap data for random selected results.

%Macro doit;

%do i =1 %to 30;

%if i > 30 %then %do;

%analysis('01jan14'd,'31jan14'd, '01-01-2014','01-31-2014')

%end;

%end;

%mend;

%DOIT

Ron_MacroMaven
Lapis Lazuli | Level 10

%macro MyMacro(n=1,base=work.output);

%put info: &=n;

*process;

%put remove this line with no ending semicolon

proc append data = &syslast

           base = &base;

run;

%mend;

%macro do_this(upperbound=60;

%do i = 1 %to &upperbound;

    %put My_macro(n = &i)

    %end;

%mend;

%do_this(upperbound = 3)

for loops with dates see this page

http://www.sascommunity.org/wiki/Macro_Loops_with_Dates

Ron Fehd  macro loop maven

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 11 replies
  • 1668 views
  • 0 likes
  • 6 in conversation