SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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