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.
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.
> For some reason
Fix that.
1. What does the log say?
2. It seems you already have a variable STATUS.
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
What, in this case, would a and b represent?
> For some reason
Fix that.
1. What does the log say?
2. It seems you already have a variable STATUS.
Yep, there was another variable STATUS. THANK YOU!
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:

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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.