I am trying to run a crosstabs against the table I imported after changing my format. I have the import and format correct, why can I not run a crosstabs? Below is my program ( I removed the datafile name)
proc import
OUT=mylib.a
DATAFILE=
DBMS=xlsx REPLACE;
SHEET= 'Sheet1';
GETNAMES=YES;
RUN;
proc format;
value $Race 'C' = 'Caucasian'
'AA' = 'African American'
'A' = 'Asian'
'O', 'U'= 'Other/Unknown';
value $Used_a_recommendation 'Yes' = 'Yes'
'No' = 'No'
'N/A' = 'N/A';
run;
proc freq data = mylib.a;
tables Used_a_recommendation*Race /list missing;
format $Used_a_recommendation. $Race.;
run;
For the format statement try this pattern (you have to specify the variable if the format is not applied in another way):
format Used_a_recommendation $Used_a_recommendation. ;
Perfect! That worked. Thank you so much!
As @svh indicates, you have to tell SAS which variable will use which format.
format Used_a_recommendation $Used_a_recommendation. Race $Race.;
This makes sense when you realize SAS supplies a large number of formats and multiple variables can use the same format. You decide which otherwise you get a generic best. format for numeric and $ for character variables.
Your log would show an error similar to this:
743 format $Used_a_recommendation. $Race.; ----------------------- 22 76 ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 76-322: Syntax error, statement will be ignored.
The underscores are indicating that BEFORE the format name SAS expects something to indicate which variable(s) to apply the format to. "a name" means the name of one or more variables, the other items are lists that indicate all variables, all character variables or all numeric variables. The error is generic and doesn't care that the format indicated is supposedly a character format.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.