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!
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.);
Since your program appears to have other issues please post your SAS log of the complete program and not just the last step.
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);
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!
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.
Ready to level-up your skills? Choose your own adventure.