Search code examples
sas

How to use an if/else statement to create a new column in SAS?


In SAS I want to create a new column based on some simple logic. My code is as follows:

data MyTable2;
set MyTable1;
if end_dt < 10/31/2021
then Letter_Send_dt = INTX('Month',end_dt,-2,'end')
else Letter_Send_dt = INTX('Month',end_dt,-3,'end');
format Letter_Send_dt yymmdd10.;
run;

I know my syntax must be wrong but I've searched and can't figure out what the correct syntax should look like. Thank you in advance for the help.


Solution

    • date constant specified incorrectly
    • missing semicolon
    data MyTable2;
    set MyTable1;
    
    if end_dt < "31Oct2021"d then Letter_Send_dt = INTX('Month',end_dt,-2,'end');
    else Letter_Send_dt = INTX('Month',end_dt,-3,'end');
    
    format Letter_Send_dt yymmdd10.;
    
    run;