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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 558 views
  • 3 likes
  • 6 in conversation