Hi
I Created a Dataset In a Character Variable it contains character and Numeric Value,
I want to Split character and Numeric Value
I Have a dataset which is subject and result are character variable
subject | Result |
---|---|
1001 | 20 |
1002 | >50 |
1003 | Positive |
1004 | 30.5 |
I Want the Dataset to be
subject | Result | Numeric | Character |
---|---|---|---|
1001 | 20 | 20 | |
1002 | >50 | >50 | |
1003 | Positive | Positive | |
1004 | 30.5 | 30.5 |
Could Any one Help Me
The easiest way (I think) is to input the value to the numeric column using best. format. If the result is missing, store the value in the character column.
You'll have some notes in the log about invalid arguments to the input function, but that is expected.
Warning messages can be suppressed using ??
Numeric = input(result, ?? best.) ;
If numeric = . then character = result ;
Richard
Forgot that:smileyblush:.
Works only if you are using the data step, not in SQL.
Could You write the Code
The code is in my reply.
You need to add a data statement, a set statement, and a run statement at the end.
Richard
Dear
I very simple way
data x; length Result$ 20;
Result='20';output;
Result='>50';output;
Result='123Position';output;
Result='.';output;
Result='.23';output;
run;
data x; set x; v=(verify(Result,'1234567890.'))-1;l=length(trim(result));
length Numeric 8. CHARACTER $20;
if v=l then NUMERIC=result;
else CHARACTER=result;
run;
You can also investigaute into Regular expression, if you have some experience.
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.