BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
user40
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
A_Kh
Barite | Level 11

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;



View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

yabwon
Onyx | Level 15

 

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:

yabwon_0-1683190476420.png

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

 

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



A_Kh
Barite | Level 11

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;



sas-innovate-white.png

Register Today!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2360 views
  • 3 likes
  • 4 in conversation