Hi,
I made a macro for binning variables data set through do loop in SAS BASE.
%MACRO BIN();
DATA _NULL_;
SET TMP;
ARRAY VAR {*} _ALL_;
CALL SYMPUT('N', DIM(VAR));
%DO I = 1 %TO &N;
CALL SYMPUT('VN', VNAME(VAR{&I}));
CALL EXECUTE('PROC RANK DATA = TMP(KEEP = &VN) OUT = &VN._BIN GROUPS = 5 TIES = DENSE;' || 'VAR &VN;' || 'RUN;' );
%END;
RUN;
%MEND BIN;
%BIN();
Binning was done but a macro was not stop until I canceled by using task manager.
What was a problem in my code?
Thanks.
Assuming you get the logic errors worked out, so that you get even one PROC RANK to work properly ...
The program will run a long time because it generates many more PROC RANKs than you are expecting. SET TMP reads in the first observation, and then CALL EXECUTE generates PROC RANK for every variable. Then SET TMP reads in the second observation and CALL EXECUTE generates the same set of PROC RANKs over again (one for every variable). With 50 variables and 1,000 observations, you are not asking for 50 PROC RANKs. Instead, you are getting 50,000 PROC RANKs. You would need to add a STOP statement just before the RUN statement.
CALL SYMPUT('N', DIM(VAR));
%DO I = 1 %TO &N;
You set the macro variable during the data step execution phase, but try to use it in a macro statement that is resolved during the data step compilation phase.
Use a data step loop instead:
call symput('N', dim(var));
do i = 1 to dim(var);
Assuming you get the logic errors worked out, so that you get even one PROC RANK to work properly ...
The program will run a long time because it generates many more PROC RANKs than you are expecting. SET TMP reads in the first observation, and then CALL EXECUTE generates PROC RANK for every variable. Then SET TMP reads in the second observation and CALL EXECUTE generates the same set of PROC RANKs over again (one for every variable). With 50 variables and 1,000 observations, you are not asking for 50 PROC RANKs. Instead, you are getting 50,000 PROC RANKs. You would need to add a STOP statement just before the RUN statement.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.