Home > Software engineering >  Subtracting month in SAS
Subtracting month in SAS

Time:10-29

%let mth1 = '2022-05-01'; how do I get '2022-02-01' from the macro variable? I was thinking this intnx('month',&mth1.,-3) but this only works in the format of yyyymmdd

Thank you.

CodePudding user response:

You'll need to convert it into a SAS date with inputn(), but you will need to remove quotes. %sysfunc(inputn(&mth1., yymmdd10.)) will convert it to a SAS date so that it can be used in intnx().

%let mth1 = 2022-05-01;

%let mth2 = %sysfunc(intnx(month, %sysfunc(inputn(&mth1., yymmdd10.)), -3), yymmdd10.);

%put &mth2;

Output:

2022-02-01

If you do want the output in single quotes, wrap the function above with %tslit().

  • Related