BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASFNG
Calcite | Level 5

I am receiving a syntax error with the following Race format. Can you please provide some guidance?

Race is numeric and must remain numeric.


proc format;

value Race

Caucasian = 'White'

Black,Asian,not entered,other ='Other';

proc freq data=combine;

tables Doselot Wt_Cat Race*Weight / nocum;

format Race Race.;

1 ACCEPTED SOLUTION

Accepted Solutions
TashaChapman
Fluorite | Level 6

That is 100% correct.  Formats, even formats applied to a variable in a DATA step and part of the dataset attributes, do not change the underlying values of the variable.  So even if it prints as "Caucasian" the unformmatted value should still be 1.  This unformmatted value is what you need to use in your new format statement.

View solution in original post

20 REPLIES 20
art297
Opal | Level 21

It is a character field, thus you have to precede the format name with a $  e.g.,

proc format;

value $Race

Caucasian = 'White'

Black,Asian,not entered,other ='Other';

run;

proc freq data=combine;

tables Doselot Wt_Cat Race*Weight / nocum;

format Race $Race.;

run;

Astounding
PROC Star

In addition, consider ...

You'll need quotes around values that get translated:

value $Race

'Caucasian' = 'White'

'Black', 'Asian', 'not entered', other='Other';

What does "not entered" mean?  Does it mean that RACE actually contains the characters "not entered" or does it mean RACE is blank?

What does "other" mean?  Does it mean that RACE actually contains the characters "other" or does it mean that RACE contains something else such as Hispanic?

Capitalization is important.  The format will look for an exact match between the format definition and the data values for RACE.

All of these issues can affect how you code the VALUE statement.

ballardw
Super User

I thought the quotes on the source were required but not so when I tested with SAS 9.2

I'm familiar with several data sources that will export a text field of 'not entered' or similar when an option button or other widget in a data base is not activated or no choice made from a group. Ugly but true.

I usually use an infomat to make these a numeric so I can assign things like 'not entered' to missing as 'Other', at least with my data sources race codes means either multi-racial or a respondant insisted on something other than the planned single racial codes.

Astounding
PROC Star

Interesting.  I tried it under 9.3 and got the same results ... quotes are not needed.

Just to explore, I tried defining the format in two ways:

other='Other'

'other'='Other'

Without the quotes around other, it was treated as all other values not defined by the format.  Adding the quotes around other limited that category to just the letters "other".

FWIW

SASFNG
Calcite | Level 5

In a previous formatting statement I created the numeric value of Race
proc format;

     value Race

          1     =     'Caucasian'

          2     =     'Black'

etc. so it is a numeric variable. I even double checked in the variables properties.

And, yes 'Not Entered' and 'Other' are actual characters in the Race value.

art297
Opal | Level 21

Maybe you can teach me/us something: How does one enter 'Not Entered' into a numeric field?

Peter_C
Rhodochrosite | Level 12

if the field is controlled by a SAS application (I recall them using informats), these can tolerate values that appear to be non-numeric. These non-numeric values  wou;ld be treated and assigned special numeric values, or even special missing values - all with no fuss.

I do not know if such fuctionality has been extended to html or java applications


art297
Opal | Level 21

,

You have caught my attention and may be teaching me something today.  Are you saying that character fields, that contain some kind of special numeric value, wouldn't require a character format?

If so, please point me in the direction of what to read.

Thanks,

Art

p.s.  Are you going to be at SGF this year?

Peter_C
Rhodochrosite | Level 12

Art

an informat can convert a string into a number

Which informat is appropriate for these?

1.2

1:2

01-02-03

?????????

Well, all could be read with either 8. or  $8. or anydttme. - not always with a useful result Smiley Wink

But they are all typed into a box as characters

another example

age-not-admitted

used to be a special string for date-of-birth, when a lady's modesty was "tolerated" by insurance companies

And in SAS we would use a special informat accepting that string as .N and other strings were informatted by the DATE informat

value anadate   'age-not-admitted' = .N other =[date9.] ;

See you in SASGF

(not long now!)

(for completing 2 papers and presentations Smiley Happy

peterC

art297
Opal | Level 21

: Speaking of SGF, I'll either be presenting 0, 1 or 2 papers, depending upon decisions that have yet to be made.  I didn't have anything to submit before the deadline, but KSharp suggested something that led to two papers, one of which has already been accepted as a feature presentation at the next MWSUG meeting.  I've submitted both to a couple of the section chairs and, hopefully, will still get a chance to present them in SF.

Minimally, I'll be presenting the SAS-L stats at the combined SAS-L/SAS Discussion Forums/sasCommunity.org/sasCanadaCommunity/(and maybe)SASProfessionals meetup Tuesday night at 6:30pm.

Last year, SASProfessionals could only present via a pre-recorded video.  Are you interested in co-ordinating and presenting their stats this year?  Don Henderson will be presenting the stats for sasCommunity.org, Art Carpenter will be presenting the stats for the Discussion Forums, and Matt Malczewski will be presenting the stats for the sasCanadaCommunity.

Art

SASFNG
Calcite | Level 5

I seriously doubt I could teach you anything...relating to SAS. Smiley Happy I am sure this is my error.

art297
Opal | Level 21

You would be surprised.  NONE of us know everything about SAS!  And I would include the developers, as well, in that comment.

Even after 40 years of using SAS, I am still learning new things every day.

SASFNG
Calcite | Level 5

As a newbie, that scares me. Smiley Happy

But, I think I get it. Even though I previously applied and activated a format, the original numeric values for Race are still there and I should use those again?

1 = 'White'

2, 3, 4 = 'other'?

TashaChapman
Fluorite | Level 6

That is 100% correct.  Formats, even formats applied to a variable in a DATA step and part of the dataset attributes, do not change the underlying values of the variable.  So even if it prints as "Caucasian" the unformmatted value should still be 1.  This unformmatted value is what you need to use in your new format statement.

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 20 replies
  • 2121 views
  • 4 likes
  • 6 in conversation