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