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;
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?
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;
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
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.