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
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!
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.