BookmarkSubscribeRSS Feed
sree0203
Calcite | Level 5
Hi,

To convert categorical variables to numbers I have used the following code in my program

If brand="minute.maid" then mid=1;
Else if brand =^"minte.maid" then mid =0;

But in the output for mid variable all the fileds with 1 are appearing and fields with 0 are appearing missing values.

Inorder to evade this I have used options missing ="0"

But while I am proc reg funtion the zero values are still getting considered as missing variables only.

How to get rid of this problem?

(Sent from handheld device please bear with typos)
4 REPLIES 4
Astounding
PROC Star

You have the characters in reverse order.  To get "not equal" you can use:

 

ne

^=

 

But not:

 

=^

Reeza
Super User

@sree0203 wrote:
Hi,




But in the output for mid variable all the fileds with 1 are appearing and fields with 0 are appearing missing values.

Inorder to evade this I have used options missing ="0"



 

No, it means you have missing values not 0, which indicates something is wrong with your code. Fix your IF/THEN statement as indicated by @Astoundingso you get 0's not missing values.  

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Simplfy your if statement and you will get the correct answer.  Binary choices are best mae using ifn/ifc:

mid=ifn(brand="minute.maid",1,0);
ballardw
Super User

Perhaps

Else if missing( brand)  then mid =0;

 

If you have many of these types of operations to do you might consider a custom informat.

proc format library=work;
invalue missingtext
. = 0
other=1;
run;

data example;
   x= ' ';
   yx=input(x,missingtext.);
   z='anything';
   yz=input(z,missingtext.);
run;

This informat looks at an input string, if it is missing then the result is 0 anything else is 1. Even if the input string has a leading blank the result is one.

 

For your use then you would have

mid=input(brand,missingtext.);

NOTE this works if you are interested in knowing that your variable has some text.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 1116 views
  • 4 likes
  • 5 in conversation