DATA Step, Macro, Functions and more

Doubt regarding compile/execution time features...

Reply
Contributor msg
Contributor
Posts: 21

Doubt regarding compile/execution time features...

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Doubt regarding compile/execution time features...

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
PROC Star
Posts: 1,566

Re: Doubt regarding compile/execution time features...

In other words, length() assesses a string (after trimming it), not a variable characteristics.
Ask a Question
Discussion stats
  • 2 replies
  • 111 views
  • 0 likes
  • 3 in conversation