I can't covert all of my data into numeric in SAS version 9. I cleaned all my data and made the character values numerical manually and now I'm trying to get the proc contents to read it as numerical so I can perform statistical tests. This is the code I have been using
I used proc print to check that my data was correct. NEWLOG2 refers to the new variable that is numeric and LOG2 is the original edited variable that now has all numerical values. 1.59 was original included text but won't covert over numerically in the new variable. PLEASE HELP!!!!
newlog1 = log1 + 0;
Your code and words refer to NEWLOG1 but your image shows NEWLOG2 and LOG2?
Where does your data originate from? A text, XLSX, SAS file?
REDCAP - then exported into excel - then exported into SAS. Excel is the main source.
Redcap can generate a CSV file instead - if the file is in the same format everytime and you're doing this often I'd strongly suggest fixing the import step instead of manually recoding things.
Did you get errors from the INPUT() function for the lines that generated missing values?
Either your values are right aligned so that the first 5 characters do not have any value or they have some "invisible" characters that are causing the text to not look like numbers.
First, use 32. or even better COMMA32. as your INFORMAT. (Note BEST is a FORMAT and not an INFORMAT).
Second remove the spaces and/or non digits from the string.
data want ;
infile cards truncover ;
input str $char50. ;
if _n_=1 then str='A0'x||str;
if _n_=2 then str=strip(str)||'0D'x;
num1 = input(str,??5.);
num2 = input(compress(str,'($,ED.)','kd'),??comma32.);
put num1= best9. @15 num2=best9. @30 str=:$quote.;
cards;
3456
4567
456.123
5677
1.234E3
(123,345)
;
num1=. num2=3456 str=" 3456" num1=. num2=4567 str="4567 " num1=456.1 num2=456.123 str="456.123" num1=. num2=5677 str=" 5677" num1=1.234 num2=1234 str="1.234E3" num1=. num2=-123345 str="(123,345)"
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.