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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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