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

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.

 

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
  • 1112 views
  • 0 likes
  • 4 in conversation