## Psuedo Code

Solved
Occasional Contributor
Posts: 13

# Psuedo Code

Can any one knows how to convert below SAS to Pseudo code ?

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.

Accepted Solutions
Solution
‎05-21-2018 05:15 AM
Super User
Posts: 10,530

## Re: Psuedo Code

Giving that awful spaghetti code some visual structure (and removing several unnecessary brackets) makes understanding it much easier:

```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```

You assign a sum (over several observations, possibly determined by a group by option) to a new variable named con_temp.

This sum is built from the term "temp * SAL_OBL" whenever all the conditions in the when are met.

Hint: this function

`intnx('month', "PAR_FEC"d, -1, 'end')`

won't work, as the text PAR_FEC is no valid SAS data literal. I suspect this should be a macro variable call &PAR_FEC instead.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Super User
Posts: 9,802

## Re: Psuedo Code

Pseudocode just means sort of code.  There is no defined standard for what that should be.  What you provide there could be pseudocode for how to write an if statement in a datastep for instance.  So no, there is no way to provide something you expect which only you know.

Solution
‎05-21-2018 05:15 AM
Super User
Posts: 10,530

## Re: Psuedo Code

Giving that awful spaghetti code some visual structure (and removing several unnecessary brackets) makes understanding it much easier:

```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```

You assign a sum (over several observations, possibly determined by a group by option) to a new variable named con_temp.

This sum is built from the term "temp * SAL_OBL" whenever all the conditions in the when are met.

Hint: this function

`intnx('month', "PAR_FEC"d, -1, 'end')`

won't work, as the text PAR_FEC is no valid SAS data literal. I suspect this should be a macro variable call &PAR_FEC instead.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 13

## Re: Psuedo Code

Hi

Thanks a lot for your solution.

☑ This topic is solved.