How to execute multiple case when statements for each iteration in SAS?
<p>I'm using proc sql, and using multiple case when statements to add columns with either a 0 or 1 if the condition is met. It's a big bottleneck right now since it has to scan through each id for each case when statement. So I'm trying to figure out a way to somehow nest the case statements to perform each iteration, instead of having to iterate for all case statements. </p>

<p>This is an example of my code that is taking too long right now.</p>

<pre><code>SELECT *,
        CASE WHEN loannumber IN (
            SELECT loannumber FROM PREPAY_LOAN_IDS
        ) THEN 1
        ELSE 0 END AS PREPAY_FLAG,

        CASE WHEN loannumber IN (
            SELECT loannumber FROM DPD_30_IDS
        ) THEN 1    
        ELSE 0 END AS DPD_30_FLAG,

        CASE WHEN loannumber IN (
            SELECT loannumber FROM DPD_60_IDS
        ) THEN 1
        ELSE 0 END AS DPD_60_FLAG,

        CASE WHEN loannumber IN (
            SELECT loannumber FROM DPD_90_IDS
        ) THEN 1    
        ELSE 0 END AS DPD_90_FLAG,

        CASE WHEN loannumber IN (
            SELECT loannumber FROM DPD_120_IDS
        ) THEN 1
        ELSE 0 END AS DPD_120_FLAG,

        CASE WHEN loannumber IN (
            SELECT loannumber FROM FORECLOSURE_IDS
        ) THEN 1    
        ELSE 0 END AS FORECLOSURE_FLAG

FROM(
    SELECT *
    FROM MORTGAGES
    )
</code></pre>