Am I doing something wrong here? How to get rid of the error?
options MINOPERATOR;
%macro validation;
%if %sysfunc(exist(IFPART.BALANCE_SEGMENT) %then;
%do;
%if ACCOUNT_PERIOD is . % then
%do;
data MVP3;
ERR_MSG_TXT='ACCOUNT_PERIOD cannot be missing';
FLT_Id=1;
FLT_REC_ID=1;
FLT_REC_TXT='faulty conctenated Business key values'
run;
%end;
%else
%do;
data _null_;
%put "ACCOUNT_PERIOD is not missing";
run;
%end;
%mend;
%validation;
ERROR:
30 %do;
ERROR: Macro keyword DO appears as text.
ERROR: A dummy macro will be compiled.
31 %if ACCOUNT_PERIOD is . % then
ERROR: Macro keyword IF appears as text.
32 %do;
33 data MVP3;
34 ERR_MSG_TXT='ACCOUNT_PERIOD cannot be missing';
35 FLT_Id=1;
36 FLT_REC_ID=1;
37 FLT_REC_TXT='faulty conctenated Business key values'
38 run;
39 %end;
ERROR: Macro keyword END appears as text.
40 %else
ERROR: There is no matching %IF statement for the %ELSE.
41 %do;
ERROR: Macro keyword DO appears as text.
42 data _null_;
43 %put "ACCOUNT_PERIOD is not missing";
ERROR: Macro keyword PUT appears as text.
44 run;
45 %end;
2
ERROR: Macro keyword END appears as text.
46
47 %mend;
ERROR: Macro keyword MEND appears as text.
48
49 %validation;
@David_Billa wrote:
Am I doing something wrong here? How to get rid of the error?
options MINOPERATOR; %macro validation; %if %sysfunc(exist(IFPART.BALANCE_SEGMENT) %then; %do;
You are missing a parenthesis above. Also, there is no semi-colon after %THEN
There are a lot of problems with that code. The one that is causing the error messages is the missing closing right parentheses from the %SYSFUNC() macro function call.
But the real mistake is this %IF statement:
%if ACCOUNT_PERIOD is . % then %do;
That can never be true since the two strings you are comparing are not the same. One is long and starts with a capital letter A and the other is just the single character period.
Did you somehow what to test the value of the ACCOUNT_PERIOD variable in the dataset?
Or did you have some macro variable named ACCOUNT_PERIOD and you just forgot to prefix the name with & so you could reference the value.
Similarly there is no need for the DATA and RUN statements in this block of code:
%else %do;
data _null_;
%put "ACCOUNT_PERIOD is not missing";
run;
%end;
Please explain what you are trying to do.
@David_Billa wrote:
In the else part I'm trying a note in the SAS log
Don't just state the very obvious.
What is ACCOUNT_PERIOD, and where does it come from?
After you fixed the issues mentioned by @PaigeMiller, you will have to check the line
%if ACCOUNT_PERIOD is . % then
The first problem is the blank between % and "then", the second problem is the expression ... you will have to read the documentation to get it working.
@andreas_lds wrote:
After you fixed the issues mentioned by @PaigeMiller, you will have to check the line
%if ACCOUNT_PERIOD is . % then
The first problem is the blank between % and "then", the second problem is the expression ... you will have to read the documentation to get it working.
Yes, there are many problems here, including referring to ACCOUNT_PERIOD which doesn't seem to be defined but appears to be a data step variable, and then mixing and matching data step and macro language improperly.
Since we don't really know what the code is supposed to do, I Point out that it is possible (depending on what the code is supposed to do) that no macros are needed here, and no macro variables are needed here. Which would simplify everything greatly.
I also don't recall the "is" operator,
Bart
options MINOPERATOR;
%macro validation(x);
%if (&x. is 1) %then
%do;
data test;
run;
%end;
%mend;
%validation(1);
143 options MINOPERATOR;
144 %macro validation(x);
145 %if (&x. is 1) %then
146 %do;
147 data test;
148 run;
149 %end;
150 %mend;
151
152 %validation(1);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: (&x. is 1)
ERROR: The macro VALIDATION will stop executing.
Just started reading 'python for SAS users', looks like python has an is operator, separate from == operator. Interesting... https://www.geeksforgeeks.org/difference-operator-python/
The is operator compares the identity of two objects while the == operator compares the values of two objects. There is a difference in meaning between equal and identical. And this difference is important when you want to understand how Python's is and == comparison operators behave. The == operator is used when the values of two operands are equal, then the condition becomes true. The is operator evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
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.