I have visit numbers that are in character format. I am trying to convert those values to numeric format so they will sort properly (ascending order). The name of my visit number variable is cvisit in analysisallp.
I used the following code, did not get any errors, the new variable got created but did not do the conversion.
data consort1;
set analysisallp;
keep usubjid design invarm cvisitn;
cvisitn=input(cvisit,$2.);
run;
The data structure is as follows for consort1:
design usubjid invarm cvisitn (in consort 1 this variable is still character)
DB 1 Rx 1
DB 1 Rx 2
The column attributes for cvisitn says $2. for format and informat and the radio button for character is filled in.
I feel like there is something obvious that I am doing wrong, but can't figure out what it is. I am using SAS 9.4 TS level 1M3.
Thanks in advance for your help.
A $ infornat will create character variables. Use the 2. informat instead.
A $ infornat will create character variables. Use the 2. informat instead.
And if the variable is already character then you need to create a NEW variable to hold the numeric value. Once a variable has a type SAS really doesn't let you change it.
cvistnumeric = input(cvistn,f2.);
@PaulaC wrote:
thank you. So the f will hold the numeric value?
F is another way to refer to the w.d informat. It basically says, expect to read two characters into a number and does not expect any decimals, i.e integers from -9 to 99.
I simply don't like not referencing a more explicit format or informat name: 2. or best2. would also work.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.