BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

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;

 

 

10 REPLIES 10
PaigeMiller
Diamond | Level 26

@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

--
Paige Miller
Tom
Super User Tom
Super User

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
Rhodochrosite | Level 12
In the else part I'm trying a note in the SAS log
Kurt_Bremser
Super User

@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?

 

andreas_lds
Jade | Level 19

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.

PaigeMiller
Diamond | Level 26

@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.

 

 

--
Paige Miller
yabwon
Onyx | Level 15

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.
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Quentin
Super User

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 Boston Area SAS Users Group is hosting free webinars!
Next up: Lisa Mendez & Richann Watson present Get Tipsy with Debugging Tips for SAS® Code: The After Party on Wednesday Jul 16.
Register now at https://www.basug.org/events.
yabwon
Onyx | Level 15
I think it is because how Python handles situation like:

x = 1
y = x

vs.

x = 1
y = 1

all the best
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



bennetcole
Calcite | Level 5

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 10 replies
  • 2442 views
  • 3 likes
  • 8 in conversation