I have to use proc summary multiple times in the program. so i wrote this macro. The macro is acting funny. Weight_var when ran simultaneously with weights given and no weights given, the macro is giving different results every time. Sometimes its right, sometimes its wrong. I know I have a lot of DO loops in this code, wanted to understand what is going wrong at times, maybe i am missing something fundamentally or is it too many loops confusing the code. I am writing two different macros where weight is present and where weight is not present for the program. but wanted to understand what is going wrong in this code at times for basics understanding. Thank you for the help. %MACRO PROC_SUMMARY_CALS(INPUT_FILE, CLASS_VARS, WEIGHT_VAR, VARS, OPERATION_VARS, OUTPUT_FILE); PROC SUMMARY DATA = &INPUT_FILE. NWAY MISSING; CLASS &CLASS_VARS.; %IF &WEIGHT_VAR. NE . %THEN %DO; /* ACTIVATE WEIGHT ONLY IF WEIGHT_VAR IS NOT EMPTY */ WEIGHT &WEIGHT_VAR.; %END; VAR &VARS.; %LET NUM_VARS = %SYSFUNC(COUNTW(&VARS.)); /* COUNTING THE NUMBER OF VARIABLES IN THE LIST */ %LET NUM_OPS = %SYSFUNC(COUNTW(&OPERATION_VARS.)); /* COUNTING NUMBER OF OPERATIONS */ OUTPUT OUT= &OUTPUT_FILE. %DO I = 1 %TO &NUM_OPS.; /* LOOP FOR READING OPERATIONS LIST LIKE MEAN, SUM, ETC. ALL STATS TYPES */ %LET OPERATION_ACTIVE = %SCAN(&OPERATION_VARS., &I); %DO J = 1 %TO &NUM_VARS.; /* LOOP FOR READING VARIABLES TO PERFORM OPERATIONS ON */ %LET VAR_ACTIVE = %SCAN(&VARS., &J); %IF %BQUOTE(&WEIGHT_VAR.) NE %THEN %DO; &OPERATION_ACTIVE.(&VAR_ACTIVE.) = &OPERATION_ACTIVE._&VAR_ACTIVE._VW %END; %ELSE %DO; &OPERATION_ACTIVE.(&VAR_ACTIVE.) = &OPERATION_ACTIVE._&VAR_ACTIVE._EW; %END; %END; %END; ; RUN; %MEND PROC_SUMMARY_CALS; %PROC_SUMMARY_CALS(INPUT_FILE=, CLASS_VARS=, WEIGHT_VAR=, VARS=, OPERATION_VARS=, OUTPUT_FILE=);
... View more