BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
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!
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26
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

View solution in original post

4 REPLIES 4
Cynthia_sas
Diamond | Level 26
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
deleted_user
Not applicable
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?
Cynthia_sas
Diamond | Level 26
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]
twocanbazza
Quartz | Level 8
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 53592 views
  • 2 likes
  • 3 in conversation