BookmarkSubscribeRSS Feed
camigyrl161
Calcite | Level 5

I am trying to convert a character variable to a numeric variable using the input statement. It is the first line of my code after importing my data and running proc contents. However, when I use the code below, the 'input' does not turn blue, and nothing changes in my log or resulting proc contents when I run the code. 

 

*change character variable to numeric;

data work.dtgdata1;
set library.dtgdata;
hiv_years = input(hivyears, $3.);
run;

 

'Input' will turn blue if it is written at the beginning of a line of code, but not after an equal sign, and I'm not sure what other methods to use to create a numeric variable. If someone could offer some insight about this I would appreciate it!

4 REPLIES 4
SASKiwi
PROC Star

I'd wouldn't get too hung up on SAS editor colour coding. The proof in whether your program works or not is in your SAS log and output - no errors, warnings and the expected output is found.

 

BTW, your INPUT function should use a numeric INFORMAT (no dollar sign) if you want a numeric result: hiv_years = input(hivyears, 3.);

camigyrl161
Calcite | Level 5
Unfortunately I don't think the code is working--the log makes no mention of "character values were changed to numeric" or anything like that, and then the data set reports out with 0 observations. I was describing the color to indicate that I think there is a specific problem with the input function after an equal sign, as it turns blue and my log is correct when I use input as the first word in the line of code.
Thank you for pointing out the INFORMAT mistake--I made that change but it still doesn't seem to be fixing the problem.
SASKiwi
PROC Star

Since your program appears to have other issues please post your SAS log of the complete program and not just the last step.

Tom
Super User Tom
Super User

Your program does not have an input statement. Instead you have an assignment state where the value being assigned is the result of the INPUT() function.  It is not clear what editor you are using, but the SAS Display Manager's "enchanced" editor does not color code function names. 

 

You INPUT function call is just taking the first three characters from the variable HIVYEARS.  The $ informat simply converts text into text. It would be clearer to use the substr() function (or the newer substrn() function).

hiv_years = substr(hivyears,1,3);

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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