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?
IF you want to refer to a macro variable value you need to prefix it with an ampersand:
%IF &I NE &J %THEN;
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
%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
You probably want %time(&k,&L); as well.
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.
%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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.