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

Hi there

I'm trying to convert a character string - which is in fact numeric, into numeric - 0.74144, 3.533, 4.578612

I've tried SLOPE_DEG = INPUT(SLOPE_DEG,6.4); but this just returns empty spaces.

Any ideas?

Thanks

Mat

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

If you convert character to numeric, you must create a new variable. SLOPE_DEG is of type character and will stay type character.

data have;
input slope_deg $;
cards;
0.74144
3.533
4.578612
;
run;

data want;
set have;
slope_deg_num = input(slope_deg,best.);
run;

proc print;run;

returns this output:

       slope_       slope_
Obs    deg         deg_num

 1     0.74144     0.74144
 2     3.533       3.53300
 3     4.578612    4.57861

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

If you convert character to numeric, you must create a new variable. SLOPE_DEG is of type character and will stay type character.

data have;
input slope_deg $;
cards;
0.74144
3.533
4.578612
;
run;

data want;
set have;
slope_deg_num = input(slope_deg,best.);
run;

proc print;run;

returns this output:

       slope_       slope_
Obs    deg         deg_num

 1     0.74144     0.74144
 2     3.533       3.53300
 3     4.578612    4.57861
lion87
Fluorite | Level 6
Thanks so much, fast reply!
Reeza
Super User

Use best12. Or best32 as your informat. 

 

Setting it to 6.4 tells SAS to look for an number that has 5 digits + 1 decimal point for a width of 6 and 4 of those 5 digits are after the decimal point. That's not your format based on the samples you've posted. . 

lion87
Fluorite | Level 6
Thanks, awesome help!

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
  • 4 replies
  • 1318 views
  • 5 likes
  • 3 in conversation