Home > OS >  Convert SAS if else to python if else
Convert SAS if else to python if else

Time:02-05

I am converting SAS script to Python and there's a if then else statement that I would like to convert to Python.

Its something like

if mi_proceeds<=1 then mi_coverage =0.01; else mi_coverage = (mi_proceeds/claim_amt)

if mi_coverage<0.01 then mi_coverage=0.01; else if mi_coverage>0.01 then mi_coverage=1.00

CodePudding user response:

Its an odd bit of code, but yeah the answer is very simple.

SAS: if mi_proceeds<=1 then mi_coverage =0.01; else mi_coverage = (mi_proceeds/claim_amt)
if mi_coverage<0.01 then mi_coverage=0.01; else if mi_coverage>0.01 then mi_coverage=1.00

python:

if mi_proceeds<=1:  
    mi_coverage =0.01  
else:  
    mi_coverage = (mi_proceeds/claim_amt)  

if mi_coverage<0.01:  
    mi_coverage=0.01  
elif mi_coverage>0.01:  
    mi_coverage=1.00

CodePudding user response:

You are not very clear on what you actually want to do, but I suspect you are not asking how to write python if statements, like some commenters seem to, but rather you are probably asking how to write a compiler for this task.

Beware, I am not very well acquainted with SAS. The solution might not be as straightforward as one might think. In a vacuum, it's just a regular language: replace then with :\n\t, ; else with \n else: \n\t. However, in practice, python's indentation makes the task slightly more difficult. The parsed result will depend on the surrounding indentation.

  •  Tags:  
  • Related