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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

6 REPLIES 6
ballardw
Super User

if put(province,provFmt.) in ('NL', 'NS') then ...

Astounding
PROC Star

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.

RattyRatskin
Calcite | Level 5

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

ballardw
Super User

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;

RattyRatskin
Calcite | Level 5

Thanks, ballardw.

Tom
Super User Tom
Super User

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

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