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
SAS Super FREQ
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
SAS Super FREQ
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
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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