Do loop macro

Reply
New Contributor
Posts: 4

Do loop macro

I am trying to feed the values k =1-100 and l = 1-100 into another macro called 'time' where K NOT EQUAL L.

This is what I have so far.

The script is erroring because it is trying to feed in characters 'K' & 'L' instead of their integer values.

%MACRO PARAMETERS;

%DO K = 1 %TO 100 %BY 1;

       %DO L = 1 %TO 100 %BY 1;

            %IF I NE J %THEN;

            %TIME(K, L);

            %ELSE;

       %END;

%END;

%MEND;

%PARAMETERS;

Can anyone help?

Super User
Posts: 5,435

Re: Do loop macro

Posted in reply to knobbyno8

IF you want to refer to a macro variable value you need to prefix it with an ampersand:

%IF &I NE &J %THEN;

Data never sleeps
New Contributor
Posts: 4

Re: Do loop macro

Thanks this has helped one problem.

Can I only use IF THEN ELSE statements in datasteps?

I don't want to create a dataset here just want to put a conditional clause on running my macro.

Cheers

Super Contributor
Posts: 644

Re: Do loop macro

Posted in reply to knobbyno8

%if %then %else are macro statements only valid within a macro (unlike say %let which can be in open code).

if then else are data step statements, only valid within a data step.

You have to be very careful not to mix the two, especially if you have a data step within a macro.

Richard

Message was edited by: Richard Carson

Super User
Posts: 11,343

Re: Do loop macro

Posted in reply to knobbyno8

You probably want %time(&k,&L); as well.

Super User
Super User
Posts: 7,074

Re: Do loop macro

Posted in reply to knobbyno8

You are not coding the %IF/%THEN code properly.

Syntax is:

%if <condition> %then <statement> ;

In your code ( %IF I NE J %THEN;) you have left the <statement> part empty.

Frequent Contributor
Posts: 106

Re: Do loop macro

Posted in reply to knobbyno8

%macro time(a,b);

%put here in time a=&a;

%put here in time b=&b;

%mend;

%MACRO PARAMETERS;

%DO K = 1 %TO 100 ;

       %DO L = 1 %TO 100 ;

             %IF &K. NE &L. %THEN

            %TIME(&K,&L);

   %ELSE

  %put entered in else Smiley Happy;

       %END;

%END;

%MEND;

%PARAMETERS;

Ask a Question
Discussion stats
  • 6 replies
  • 268 views
  • 3 likes
  • 6 in conversation