03-07-2018 03:11 PM
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)
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';
proc freq data = mylib.a;
tables Used_a_recommendation*Race /list missing;
format $Used_a_recommendation. $Race.;
03-07-2018 03:15 PM
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. ;
03-07-2018 03:23 PM
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.