Hello.
I want to change format in an existing variable that have length $9. but i Need the informat format to be longer than this to include all of the text of the variable name. How can I change informat length for an existing variable in SAS?
From what you describing I understood that you need more length for existing variable to avoid data truncation. Check this post where @SASJedi gives multiple examples to alter existing variable length and format. You might find there what you are looking for.
E.g.
/*altering Variable length*/
data class;
set sashelp.class(keep=sex);
run;
proc sql;
alter table class
modify sex char(15);
quit;
data test;
length sex $15;
sex= 'female,male';
run;
data want;
set class test;
proc print;run;
/*without altering Variable length*/
data class;
set sashelp.class(keep=sex);
run;
data test;
length sex $15;
sex= 'female,male';
run;
data want;
set class test;
proc print;run;
Changing the informat of an existing variable has no effect. Informats play a role only when the data is read initially from a text file, or when used in an INPUT function to create a new variable.
If data was truncated while being read into SAS, you need to go back to that process and fix it there.
Informat/format length are totally independent from variable length. You can have variable of length 9 (9 bytes of memory to store data) and informat/format of "arbitrary" length.
Take a look:
data test;
length n 8 c $ 9;
n=42;
c="abcdefghi";
format n 32. c $32767.;
informat n 32. c $32767.;
run;
proc contents data=test;
run;
the output from proc contents shows:
Character variable c has length of 9 bytes but format and informat are set to 32767, for numeric n it is 8 vs. 32.
The length of format is just one of information on how to present data.
BTW. that data step is an example how to set length, format and informat. (not only way to do it, but "simplest", an alternative is to use Proc Datasets [especiall when you have larger dataset]).
Bart
From what you describing I understood that you need more length for existing variable to avoid data truncation. Check this post where @SASJedi gives multiple examples to alter existing variable length and format. You might find there what you are looking for.
E.g.
/*altering Variable length*/
data class;
set sashelp.class(keep=sex);
run;
proc sql;
alter table class
modify sex char(15);
quit;
data test;
length sex $15;
sex= 'female,male';
run;
data want;
set class test;
proc print;run;
/*without altering Variable length*/
data class;
set sashelp.class(keep=sex);
run;
data test;
length sex $15;
sex= 'female,male';
run;
data want;
set class test;
proc print;run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.