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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.