BookmarkSubscribeRSS Feed
msg
Calcite | Level 5 msg
Calcite | Level 5
Hi,

I have a doubt regarding the length of variables during compilation/execution time.

The code,

1 data one;
2 name='AAA';
3 result=repeat(name,10);
4 length_var=length(result);
5 run;
6
7 proc contents data=one;
8 run;

Here, the output of the proc contents shows the length of the variable "result" is 200. I remember the length of the resultant variable when using "repeat" function will be 200. But, when i open the dataset "one" to see the value of "length_var" which should have the length of the variable "result", is only 33. What may the reason behind this?

The attribute length of the variable "result" is determined at compile time and the value of the variable "length_var" which is the output of the length function is determined only at execution time. Is this the reason?

Won't the SAS consider the attributes of the variable "result" when scanning the the line 4 during compile time?

Thanks
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The LENGTH function resolves with each variable interrogation (at execution time -- and on each DATA step iteration).

So, even within a single DATA step pass, you could alter the SAS CHARACTER variable contents (shorten or lengthen) and the LENGTH will report a result, based on the current contents (without considering any blank-padding) -- it does not reflect the SAS system dataset declared (or implied) variable length -- which is actually the maximum length possible, when considering truncation.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument, this topic/post:

length function character variable site:sas.com


Also, suggested SAS Base System DOC reading:

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304318.htm
ChrisNZ
Tourmaline | Level 20
In other words, length() assesses a string (after trimming it), not a variable characteristics.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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