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.) ;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.