BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
opuyfb91
Fluorite | Level 6

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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
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);
Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 984 views
  • 2 likes
  • 3 in conversation