BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

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;

NameID
A12
B25
CV13
D24

Thanks,

3 REPLIES 3
M_Maldonado
Barite | Level 11

create a new variable using the input function.

some examples here: SAS(R) 9.3 Functions and CALL Routines: Reference

Good luck,

Miguel

ballardw
Super User

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.

Steelers_In_DC
Barite | Level 11

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

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.

Discussion stats
  • 3 replies
  • 1096 views
  • 0 likes
  • 4 in conversation