Need to convert below sas code to pseudocode.

Amar M
Amar M used Ask the Experts™
Need to convert below sas code to pseudocode.

sum ((case when (mod_r in ('02') and CAL IN ('P') and fec_in <= intnx('month', "PAR_FEC"d, -1, 'end') and EST not in ('7' '07' ' 7' '7 ' '70')
              and temp>0) then temp*SAL_OBL else . end)) as con_temp.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is a fragment from SAS's implementation of SQL.  

SQL specifies what you want and not how to do it, so to show this in imperative code to be
ported into another SQL is not going to be strictly possible.

 Any way, what it is saying is to get a value from each record and provide the sum of all of them
 across the whole data set (SQL table). Call the result variable (or SQL column)  con_temp

 what gets summed from each record (or SQL row) is either the result of the calculation
 or the null value.  Adding the null value (here indicated by a dot . ) does not change the sum.

 The condition to add the calculation (and not the null value) is

 mod_r   = '02'                                                             and
 CAL       =  'P'                                                              and
 fec_in <= intnx('month', "PAR_FEC"d, -1, 'end')    and
 EST not in ('7'    '07'    ' 7'    '7 '    '70')                    and
 temp  >  0

 Because these conditions are all joined by  and  they all have to hold simultaneously in a record
 (SQL row).

 The IN condition just says that the value on the left must be one of the list of values
 (in parenthesis) on the right.  For the first 2 conditions there was only one element on the
 right so I replaced the IN ( <single element>) by  = <single element>.

 I strongly suspect you have mistyped the 3rd condition.  Perhaps the "PAR_FEC"d  should
 be "&PAR_FEC"d. Otherwise this would produce a date error.  What the 3rd condition is
 saying is that date value in fec_in   must be equal to or before the end of the
 previous month given by the incorrect parameter  "PAR_FEC"d .

 The 4th condition says that EST  must not be character '7' with or without a
 leading or trailing blank or zero.

 Because this is part of some SQL code there could well be other conditions limiting
 (or expanding) the records (SQL rows) that are subject to the summing.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial