BookmarkSubscribeRSS Feed
accintron
Obsidian | Level 7

I am looking for a simple way to exclude one variable (YEAR) from the option of _NUMERIC_ , if possible, since I keep getting the following error: ERROR: Year appears in both CLASS and VAR list.

 

I have a lot of numeric variables that I want to see the SITE_ID_*_NUMERIC tabulation for, so I want to avoid having to list them all individually. Here is my code:

 

proc tabulate data=check out=check2b;
class Site_ID_ YEAR;
var  NUMERIC_  ;
table SITE_ID_*_NUMERIC_ /
rts=32;
run;

6 REPLIES 6
Reeza
Super User

Can you use a different form of the shortcut list?

For example, use the -- notation instead?

 

Here is a reference that illustrates how to refer to variables and data sets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 

Another option may be to use PROC MEANS? It looks like you're examining the distribution/counts of your variables?

 

 

accintron
Obsidian | Level 7
I have way too many variables, but I did consider this thank you.
Rick_SAS
SAS Super FREQ

I think the simplest fix is to define a DATA VIEW that creates a character variable from YEAR, then use the VIEW in the PROC:

 

data Have / view=Have;
length Year_Char $4;
set check;
Year_Char = put(YEAR, 4.);
drop YEAR;
run;

proc tabulate data=Have out=checkb;
class SITE_ID_ Year_Char;
table SITE_ID_ * _NUMERIC_ / rts=32;
run;
accintron
Obsidian | Level 7
I'm goign to try this right now, but this seems simple enough!
Cynthia_sas
Diamond | Level 26

Hi:

  The error message you're getting is that YEAR is numeric and you've listed it twice -- once in the CLASS statement, explicitly and once in the VAR statement implicitly with _NUMERIC_. So the issue is that you'd need to make YEAR a character variable, before the TABULATE in order to do what you want. Or else, you could do a query on Dictionary tables to get the names of the variables (without the class items) into a macro variable to use in the VAR statement. _NUMERIC_ is going to include YEAR. And one of the rules of PROC TABULATE is that a variable can only have one role -- CLASS or VAR and your code is making YEAR fall into both roles, which is an ERROR.

 

Cynthia

ballardw
Super User

You can always use a DATA SET OPTION drop or keep:

 

proc tabulate data=check (drop= nameofunwantedvar) out=check2b;
class Site_ID_ YEAR;
var NUMERIC_ ;
table SITE_ID_*_NUMERIC_ /
rts=32;
run;

 

This form of drop means that for the duration of this proc ignore that variable (or variables) or alternatively use only the variables on a KEEP list. I haven't found a procedure this doesn't work with.