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.) ;
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.
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.