Hi there,
I have a 11 caracter (Length 11, Format $11., Informat $11.) long text which is '83.0000000'.
I want to convert it as 083 (character type). Can someone help please.
83.0000000 should be 083
95.0000000 should be 095
100.000000 should be 100
I wrote the following code, but it still doesn't help.
DATA Have;
A='83.00000000';
RUN;
DATA Out;
SET Have;
A=INPUT(A,z3.);
RUN;
Thanks,
Don't know why the length would matter but here it is:
data out; length a 3.;
set have(rename=(a=OldA));
a=input(OldA,3.);
format a z3.;
drop OldA;
run;
I re-wrote it a bit to preserve your variable name A using RENAME in the SET statement.
A = substr(a,1,index(a,'.')-1);
You cannot change the format of the variable in DATA step. Your variable is text in both HAVE and OUT. Also, z3. is not useful as an informat. Try this:
data have;
a='83.00000000';
run;
data out;
set have;
b=input(a,3.);
format b z3.;
run;
Don't know why the length would matter but here it is:
data out; length a 3.;
set have(rename=(a=OldA));
a=input(OldA,3.);
format a z3.;
drop OldA;
run;
I re-wrote it a bit to preserve your variable name A using RENAME in the SET statement.
SAS always stores numbers as floating point. So you can reduce the storage from 8 to 3 as long as you only have small integers.
But is sounds like you want to convert your 11 character string to a 3 character string. You can use a number as an intermediate step.
So if your original variable is named HAVE this will create a new variable named WANT that is length $3 and has the leading zeros.
want = put( input(have,11.) , Z3.) ;
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.