crosstabs using format

Reply
Occasional Contributor GS2
Occasional Contributor
Posts: 16

crosstabs using format

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;

Occasional Contributor svh
Occasional Contributor
Posts: 17

Re: crosstabs using format

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. ;

Occasional Contributor GS2
Occasional Contributor
Posts: 16

Re: crosstabs using format

Perfect! That worked. Thank you so much!

Super User
Posts: 13,498

Re: crosstabs using format

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.

 

Ask a Question
Discussion stats
  • 3 replies
  • 132 views
  • 0 likes
  • 3 in conversation