Hi,
I have numeric data representing provinces that I formatted as characters using a proc format
proc format
value provFmt 10='NL' 11='NS' ...
I can use the character value in a model statement for example but in an if statement
if province='NL' or province='NS' then ...
then I get
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
and the statement fails.
Any ideas on how to get around this?
Thanks!
RR
Many place SAS will use the formatted value if the variable was permanently associated with the format.
For use in a datastep IF you'll basically need to create a new variable with the text value.
Either a straight forward:
ProvinceText = put(province,provFmt.);
or if the variable just has to be named Province
data want;
set have (rename=(province=provnum));
Province = put(provnum,provFmt.);
/* and optionally */
drop provnum;
run;
if put(province,provFmt.) in ('NL', 'NS') then ...
By creating a format, you haven't changed the values of PROVINCE. You have only changed how they print. So the IF statement should refer to the actual values:
if province=10 or province=11 then ...
if province in (10, 11) then ...
Good luck.
Thanks, Astounding. I'm confused, though. I can use
class province(ref='NL')
and that works fine...i.e. it's behaving as if 'NL' is the value (or an alias).
Anyway, is there a way to really change the values of province?
Thanks,
RB
Many place SAS will use the formatted value if the variable was permanently associated with the format.
For use in a datastep IF you'll basically need to create a new variable with the text value.
Either a straight forward:
ProvinceText = put(province,provFmt.);
or if the variable just has to be named Province
data want;
set have (rename=(province=provnum));
Province = put(provnum,provFmt.);
/* and optionally */
drop provnum;
run;
Thanks, ballardw.
Why you have to use ref='NL' instead of ref=10 is explained in this note:
37108 - Setting the reference levels for the CLASS predictor variables
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.