- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A $ infornat will create character variables. Use the 2. informat instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A $ infornat will create character variables. Use the 2. informat instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.