DATA Step, Macro, Functions and more

How to run a macro 60 times and put data into in one table?

Reply
Occasional Contributor
Posts: 5

How to run a macro 60 times and put data into in one table?

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;

Super User
Posts: 5,430

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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
PROC Star
Posts: 7,474

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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.

Occasional Contributor
Posts: 5

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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

Super User
Posts: 19,815

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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.

Occasional Contributor
Posts: 5

Re: How to run a macro 60 times and put data into in one table?

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

Super User
Posts: 19,815

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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

PROC Star
Posts: 7,474

Re: How to run a macro 60 times and put data into in one table?

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.

Super Contributor
Super Contributor
Posts: 3,174

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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.

Occasional Contributor
Posts: 5

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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;

Occasional Contributor
Posts: 5

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

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

Regular Contributor
Posts: 227

Re: How to run a macro 60 times and put data into in one table?

Posted in reply to XiaoyanZhao

%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

Ask a Question
Discussion stats
  • 11 replies
  • 484 views
  • 0 likes
  • 6 in conversation