Hi there,
I have the following data set and I wonder if someone can tell me the Code to change the ID column from Character to Numeric so that I can do analysis. My problem is I have some value under ID column that are combination of character and numeric (eg. V13), therefore consider the whole column as text.
The analysis code for my analysis is:
Data Have;
set Out;
where ID between 12 and 24;
run;
Name | ID |
A | 12 |
B | 25 |
C | V13 |
D | 24 |
Thanks,
create a new variable using the input function.
some examples here: SAS(R) 9.3 Functions and CALL Routines: Reference
Good luck,
Miguel
Or try
where ( input( ID,best6.)) between 12 and 24;
though if you expect to get V13 in that result you'll need to do more coding to strip off the character bits before conversion.
Do you need to keep the 13 after the V? If so use the num_id line. If you want to drop anything that has a character use the new_id line. Run this and you'll see what I mean:
data have;
infile cards dsd;
input Name$ ID$;
cards;
A,12
B,25
C,V13
D,24
;
data want;
set have;
new_id = input(id,8.);
num_id = input(compress(id,'a','a'),8.);
run;
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!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.