Hi, I've read some posts and watch the tutorial, but I can figure out how to resolver my (pretty simple) problem. My original data are character format $105 (even if there are numbers) and I want to create a new variable where they would be numerics... Can you help me ? I'm confused between the input, the informat and format...
/*changer mon type de colonnes, ce sont toutes des character sauf No_ferme*/
data prx;
set pr;
DIMx=input(DIM, $8.);
run;
Here is a print screen of the data and the code.... THANKS!:)
Good that it works. A couple of points.
There is no need to limit your INFORMAT to just 8 characters. The maximum width that particular informat supports is 32 and the INPUT function does not mind if the string being converted is shorter than the informat width.
If your variable has length 105 are you sure the digits you want to read are not preceded by spaces that would force them beyond the 8th (or 32nd) character in the string? If might reduce risk to use LEFT() function to remove any leading spaces.
DIMx=input(left(DIM), 32.);
There is no bug with this code
data prx;
set pr;
DIMx=input(DIM, 8.);
run;
but my new variable is a "." for every observation....
Thanks
Good that it works. A couple of points.
There is no need to limit your INFORMAT to just 8 characters. The maximum width that particular informat supports is 32 and the INPUT function does not mind if the string being converted is shorter than the informat width.
If your variable has length 105 are you sure the digits you want to read are not preceded by spaces that would force them beyond the 8th (or 32nd) character in the string? If might reduce risk to use LEFT() function to remove any leading spaces.
DIMx=input(left(DIM), 32.);
Thanks! With that code, it is working!:)
Just change the informat from $8. to 8., since the string you're converting is a string of numbers.
data prx;
set pr;
DIMx=input(DIM, 8.);
run;
Just to take home the primary message in the replies from @mklangley and @su35: specify informats in an INPUT function reading a character variable exactly as you specify informats in an INPUT statement reading data from a text file with the same content.
So, since you would use an informat of 8. reading numerics from the external file, use it in the input function too.
You should check why the information is stored in a char-variable, at all. And why its length is 105 chars, as soon as the number has more than 15 digits you will loose precision when converting it to numeric.
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 16. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.