0
$\begingroup$

In SAS

dereferencing this does not work:

data TempTemp2&j. (keep=ITEM_CRT Product_CRT Product_GROUP Reality_&MonthDataInputBalsave_2024 Closing_01_2024); * drop all irrelevant variables;

while this does work:

data TempTemp2&j. (keep=ITEM_CRT Product_CRT Product_GROUP Reality_&ClosingThisMonth._&ClosingThisYear. ); * drop all irrelevant variables;

Any idea why? Numerical/character related?

%let ClosingThisMonth = 03;
%let ClosingThisYear = 2024;
*debugging;
%let Month = 03; *currently use one month BEFORE the month you want to do the closing for;
%let Year = 2024;

/* because indexing does not work in the retarded SAS dataset */
/*  renaming the relevant variables would actually make more sense but I tried for 2 hours and then I gave up*/
*calculate the previous month (and year);
%macro SubtractOneMonth;
    
    %if &ClosingThisMonth. = 01 %then %do;
        %let MonthDataInputBalsave = 12;
        %let YearDataInputBalsave = %eval(&ClosingThisYear - 1); /* add zero before single digit somehow */
    %end;
    %else %do;
        %let MonthDataInputBalsave = %eval(&ClosingThisMonth - 1);
        %let MonthDataInputBalsave = %sysfunc(putn(&MonthDataInputBalsave, z2.));
        %put MonthDataInputBalsave: &MonthDataInputBalsave;
        %let YearDataInputBalsave = &ClosingThisYear;
    %end;

    /* Optional: Print the result */
    %put Previous Month: &ClosingThisMonthMinusOneWithZero., Year: &YearDataInputBalsave.;
    
%mend;
%SubtractOneMonth;
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.