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

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.

1 ACCEPTED SOLUTION
5 REPLIES 5
PaulaC
Fluorite | Level 6
Thank you so much!!! I knew it was something obvious and simple. This worked! I appreciate your help. 🙂
ballardw
Super User

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
Fluorite | Level 6
thank you. So the f will hold the numeric value?
ballardw
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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