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.;
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.
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;
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.
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.
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
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.
Maybe you can teach me/us something: How does one enter 'Not Entered' into a numeric field?
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
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?
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
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
peterC
: 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
I seriously doubt I could teach you anything...relating to SAS. I am sure this is my error.
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.
As a newbie, that scares me.
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'?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.