BookmarkSubscribeRSS Feed
CathyVI
Lapis Lazuli | Level 10

Hi,

I am familiar with this issue but cant fix it. I'm getting the following error from pro tabulate:

 

WARNING: A class variable is crossed with itself in the table statement at line 867. This may cause unpredictable results.
WARNING: A class variable is crossed with itself in the table statement at line 867. This may cause unpredictable results.
NOTE: There were 5361 observations read from the data set WORK.AGE.
NOTE: PROCEDURE TABULATE used (Total process time):
real time 1.16 seconds

 

I know this is as a result of a cross tab of the same variable however, I do not know how to resolve the issue in this code (FYI: I found the code online and modified it).

 

This is a part of the code:

 

%macro do_freq_gender;
%do j=1 %to &numvars;
proc tabulate data=gender;
class gender &&var_&j. ;
table (&&var_&j. all),
(gender all='All') * (N colpctn='% of Col');
format gender sexf.
&&var_&j. &&fmt_&j.;
run;
%end;
%mend;

 

Any help please. Thanks.

4 REPLIES 4
Cynthia_sas
Diamond | Level 26
Hi: My guess is that your variable list also contains GENDER, which is a problem because you have GENDER hard-coded in the TABLE statement, so if GENDER is in your list of variables that you're looping through, when it's crossed with itself, it will generate an error. You don't show how your list &&var_&j is generated, but my guess is that you'll need to verify that GENDER is NOT in the list or else modify the macro program to skip the loop when the value of &&var_&j is equal to GENDER.
Cynthia
CathyVI
Lapis Lazuli | Level 10

@Cynthia_sas 

Thank you for the explanation. You are right, the macro is hard-coded. I do not know enough about macro to resolve this problem. Please can you provide more example as to how I can modify the macro program to skip the loop or how I can check (&&var_&j) to remove the variable. Thanks again

ballardw
Super User

@CathyVI wrote:

@Cynthia_sas 

Thank you for the explanation. You are right, the macro is hard-coded. I do not know enough about macro to resolve this problem. Please can you provide more example as to how I can modify the macro program to skip the loop or how I can check (&&var_&j) to remove the variable. Thanks again


You macro code is using multiple variables that do not appear in the macro definition so it is not easy to address. You would have to include the code used to create all of those macro variables. That would likely be the better place to address things.

 

Note that Proc Tabulate can contain multiple CLASS, VAR and Table statements. So if this code is supposed to be looping over the same data set multiple times and creating separate tables for each variable then the entire process should be looked at as each time the procedure is called with the same data set your code reloads the data. With moderate to large datasets this could result in considerable times.

Cynthia_sas
Diamond | Level 26
Yes, @ballardw is correct. It would be better to address the issue of GENDER in the code that creates &&var_&j and &&fmt_&j.
But without the data and ALL the code and some idea of the desired results, it is hard to determine whether you really need multiple PROC TABULATE steps or whether it would be better to have one PROC TABULATE with multiple TABLE statements.
Cynthia

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
  • 4 replies
  • 925 views
  • 0 likes
  • 3 in conversation