BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kalai2008
Pyrite | Level 9

How to convert the variable checkname from character to numeric?

 

Given data

Checkname
0-1_check
1-2_check

 

data want ;
set have;
checkname1=input(checkname,best12.);
run;

 

Getting missing value(Period)

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Before any programming takes place, it is up to you to decide what you would like the result to be.  For example, you might decide that when CHECKNAME is "0-1_check" that CHECKNAME1 should be 1.  There is nothing that SAS does on its own to make those decisions.

 

With just a few possible values for CHECKNAME, it might be as simple as this:

 

data want;

set have;

if checkname='0-1_check' then checkname1=1;

else if checkname='1-2_check' then checkname1=2;

run;

 

If there are many possible values to translate, you might need to create a rule that describes the outcome, instead of a list of values.  But it all starts with you making the decisions about what the result should look like.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

A numeric variable in SAS can not contain characters.

Astounding
PROC Star

Before any programming takes place, it is up to you to decide what you would like the result to be.  For example, you might decide that when CHECKNAME is "0-1_check" that CHECKNAME1 should be 1.  There is nothing that SAS does on its own to make those decisions.

 

With just a few possible values for CHECKNAME, it might be as simple as this:

 

data want;

set have;

if checkname='0-1_check' then checkname1=1;

else if checkname='1-2_check' then checkname1=2;

run;

 

If there are many possible values to translate, you might need to create a rule that describes the outcome, instead of a list of values.  But it all starts with you making the decisions about what the result should look like.

Kalai2008
Pyrite | Level 9

You are Right, (but it is already created by another user.)

Thank you , I will try renaming the variable.

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 Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 796 views
  • 0 likes
  • 3 in conversation