BookmarkSubscribeRSS Feed
knobbyno8
Calcite | Level 5

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?

6 REPLIES 6
LinusH
Tourmaline | Level 20

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
knobbyno8
Calcite | Level 5

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

RichardinOz
Quartz | Level 8

%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

ballardw
Super User

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

Tom
Super User Tom
Super User

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.

pradeepalankar
Obsidian | Level 7

%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 :);

       %END;

%END;

%MEND;

%PARAMETERS;

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
  • 6 replies
  • 949 views
  • 3 likes
  • 6 in conversation