Solved
Not applicable
Posts: 0

# Maximum lengh of a string

I have a table created with one of the fields define as:
LGC_DE CHAR(1024);
But I read that- The maximum length for a string variable to be passed on to SAS is 200 characters. Does this mean that my variable LGC_DE will nt hold more than 200 characters?

Thank you!

Accepted Solutions
Solution
‎09-07-2017 02:14 PM
SAS Super FREQ
Posts: 9,368

## Re: Maximum lengh of a string

Hi:
For some SAS functions, the former maximum length of 200 was assumed to be the length of a character string returned by the function. However, for quite a while now, the max length of a character variable, is as stated in the documentation:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a002645858.htm

A character variable is a variable whose value contains letters, numbers, and special characters, and whose length can be from 1 to 32,767 characters long.

If you need to be sure that your character variable comes across as a larger length, then use an explicit LENGTH statement:
[pre]
length longchar \$1024;
[/pre]

There are some instances, however, where the length of a character variable is set based on interface restrictions, such as this restriction when reading from Excel:
http://support.sas.com/kb/19/409.html

You may need to open a track with Tech Support if you find that you have issues with the length of your character variable.

cynthia

All Replies
Solution
‎09-07-2017 02:14 PM
SAS Super FREQ
Posts: 9,368

## Re: Maximum lengh of a string

Hi:
For some SAS functions, the former maximum length of 200 was assumed to be the length of a character string returned by the function. However, for quite a while now, the max length of a character variable, is as stated in the documentation:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a002645858.htm

A character variable is a variable whose value contains letters, numbers, and special characters, and whose length can be from 1 to 32,767 characters long.

If you need to be sure that your character variable comes across as a larger length, then use an explicit LENGTH statement:
[pre]
length longchar \$1024;
[/pre]

There are some instances, however, where the length of a character variable is set based on interface restrictions, such as this restriction when reading from Excel:
http://support.sas.com/kb/19/409.html

You may need to open a track with Tech Support if you find that you have issues with the length of your character variable.

cynthia
Not applicable
Posts: 0

## Re: Maximum lengh of a string

When you say:
"If you need to be sure that your character variable comes across as a larger length, then use an explicit LENGTH statement:

Does it mean greater than 32767 characters?
SAS Super FREQ
Posts: 9,368

## Re: Maximum lengh of a string

No, the maximum length of a string is 32767. But, consider this example of the CATX function and the use of the concatenate operator (||). By default, the concatenate operator creates the new variable with a length equal to all the concatenated pieces, while the CATX function uses a length of \$200.

If you want to ENSURE a length for your character variable, up to the maximum allowable length, then use the LENGTH statement, as shown in the code below.

cynthia
[pre]
data makechar;
length char2 \$4000 char3 \$32767 char5 \$200;
** compare the different lengths;
char1 = catx(' ','Kermit','the','Frog');
char2 = catx(' ','Kermit','the','Frog');
char3 = catx(' ','Kermit','the','Frog');
char4 = 'Kermit '||'the '||'Frog';
char5 = 'Kermit '||'the '||'Frog';
run;

proc contents data=makechar;
title 'Compare the various lengths of the character variables';
run;
[/pre]
Super Contributor
Posts: 356

## Re: Maximum lengh of a string

I am probably going to confuse the issue but

Also be carefull regarding what format is applied to the var, as if say \$200. then although the length of the var is say \$1024 you will only be able to "see" the first 200 chars due to the format.

Barry
🔒 This topic is solved and locked.

Discussion stats
• 4 replies
• 13237 views
• 0 likes
• 3 in conversation