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
Lapis Lazuli | Level 10

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
Lapis Lazuli | Level 10

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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