BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

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;

3 REPLIES 3
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

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

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Perfect! That worked. Thank you so much!

ballardw
Super User

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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 466 views
  • 0 likes
  • 3 in conversation