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

I have a dataset in which I created a new variable Status with coding of 0 and 1. For some reason, it automatically coded as character and at a length of 255. I've tried recoding it to numeric, but only get "." as the result. I can see that in the character field, the number is in the right-most position (@255). Is there a way to recode this to numeric and keep the "0" or "1" value at the 255 position? Here is where I created the variable "Status".

 

if Event="Yes" then Status=0;
else if X_Dx_Date=. then Status=0;
else Status=1;

*Event was a character value and X_Dx_Date was a date value.

 

dmwilliams_0-1638053683913.png

Tried recoding but only get that 255 is too long with this (also tried 3. instead of 255 and got "." for all values): 

numeric_var = input(Status, 255.); 
drop Status;
rename numeric_var = Status; 
run;

 

Thank you! I know this must be simple, but everything I've tried has failed.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

> For some reason

Fix that.

1. What does the log say?

2. It seems you already have a variable STATUS. 

 

View solution in original post

7 REPLIES 7
sbxkoenk
SAS Super FREQ

Use compress function to get rid of the blanks.

data abc;
a='                                                                         1';
b=input(compress(a),1.); put b=;
output;
a='                                                                         0';
b=input(compress(a),1.); put b=;
output;
run;

Koen

dmwilliams
Fluorite | Level 6

What, in this case, would a and b represent? 

ChrisNZ
Tourmaline | Level 20

> For some reason

Fix that.

1. What does the log say?

2. It seems you already have a variable STATUS. 

 

dmwilliams
Fluorite | Level 6

Yep, there was another variable STATUS. THANK YOU!

Kurt_Bremser
Super User

This code

if Event="Yes" then Status=0;
else if X_Dx_Date=. then Status=0;
else Status=1;

will create a numeric variable unless a character variable with name status is already defined in the step, either by preceding code or in an incoming dataset. To determine this, follow Maxim 2 and Read The Log. If this does not immediately give you a clue, post the whole log of the step by copy/pasting it into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

dmwilliams
Fluorite | Level 6

Yes, nothing is immediately apparent. The log has no errors, but has this:

 

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
1874:53 1875:13

ChrisNZ
Tourmaline | Level 20
How do you expect to create a numerical variable when you already have a character variable of the same name? You can't.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2188 views
  • 2 likes
  • 4 in conversation