BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChickenLittle
Obsidian | Level 7

Hi,

 

I am merely trying to convert a field containing "0" or "1" into "F" or "P". The field was formatted as a character field and when I use the Case When statement, it is not working.

What I have (MyDataSet is formatted as a character field):

Obs    Field1

1          0

2          1

3          0

 

What I want:

Obs    Field2

1          F

2          P

3          F

 

My Code:

proc sql;
create table Table_Name as select
case when Field1 = '1' then 'P'
         when Field1 = '0' then 'F' else 'N/A'
         end as Field2
from MyDataSet;
quit;
run;

 

Result I am getting from my code:

Obs    Field2

1          N/A

2          N/A

3          N/A

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So you have discovered that the actual values in FIELD1 are NOT the single digit strings '1' or '0'.

 

Perhaps FIELD1 is a number.

Perhaps FIELD1 has a format attached to it that is making the values print as '1' or '0'.

Perhaps FIELD1 values are actually a lowercase l and an uppercase O.

Perhaps FIELD1 values have leading spaces in them.

Perhaps FIELD1 values have other invisible characters, like tabs, in them.

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

So you have discovered that the actual values in FIELD1 are NOT the single digit strings '1' or '0'.

 

Perhaps FIELD1 is a number.

Perhaps FIELD1 has a format attached to it that is making the values print as '1' or '0'.

Perhaps FIELD1 values are actually a lowercase l and an uppercase O.

Perhaps FIELD1 values have leading spaces in them.

Perhaps FIELD1 values have other invisible characters, like tabs, in them.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 199 views
  • 1 like
  • 2 in conversation