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

Hello,

I have a variable that is formatted $3. Within this variable there is a value '  .' which was causing me some confusion. Initially I thought '.' was the null value for numeric, not character. However it seems this value has 2 spaces in front of it, hence '  .' , which lead me to believe it was a character

Also, when I enter the following tests:

if variable = '  .';

if variable =.;

Both return true.

Please help me to understand what this value is that I have here. What is a practical approach from a data hygiene perspective for cleaning this? How is a character variable identified as being equal to both a character value and a numeric value at the same time?

Best regards,

Mike

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

They both test true because variable is converted to numeric when tested against missing numeric dot.  See note below. 

As far as "what it is" it is exactly what it appears to be,  2 space and a period.  You can test and set to blank if LEFT(VARIABLE) eq '.' then variable='  ';

data _null_;
   variable =
'  .    ';
   y = variable eq
'  .';
   z = variable eq
.;
  
put _all_;
  
run;

NOTE:
Character values have been converted to numeric values at the places given by: (Line):(Column).
     
35:8  
variable=
. y=1 z=1 _ERROR_=0 _N_=1

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

They both test true because variable is converted to numeric when tested against missing numeric dot.  See note below. 

As far as "what it is" it is exactly what it appears to be,  2 space and a period.  You can test and set to blank if LEFT(VARIABLE) eq '.' then variable='  ';

data _null_;
   variable =
'  .    ';
   y = variable eq
'  .';
   z = variable eq
.;
  
put _all_;
  
run;

NOTE:
Character values have been converted to numeric values at the places given by: (Line):(Column).
     
35:8  
variable=
. y=1 z=1 _ERROR_=0 _N_=1
mikemangini
Obsidian | Level 7

Thank you, this clarification is helpful. I didn't realize SAS would automatically convert to numeric like that. I overlooked it in the log. This is valuable information to have.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 2 replies
  • 4271 views
  • 0 likes
  • 2 in conversation