-2

I am trying to convert the following code from sql to python:

Sql code:

%macro extract(custom_nm= );

   %if %eval(&custom_nm. ne ) %then %do;
        %put ------ ABCD ABCD ------ ;
   %end;

Converted python code:

def extract(custom_nm):

I haven't progressed after this as I can't figure out an efficient way to convert %if, %eval, %do, and %put.

According to SAS documentation guide,

%if expression should return true if the expression resolves to an integer other than zero and then %then clause is processed. If the expression resolves to zero, then the expression is false and the %else statement is proceeded, if it exists. If the expression resolves to a null value or non-numeric characters, then an error message is shown.

The conditions of the %eval in the guide are even longer.

Please someone who has dealt with similar function conversions above, let me know what you used.

Thank you, much appreciated.

1 Answers1

1

This is just an ordinary if statement.

def extract(s):
    if s:
        print("------ ABCD ABCD ------")
Barmar
  • 741,623
  • 53
  • 500
  • 612