As I see it, it depends. But, everything is in fact done at compile time.
On most times, SAS will manage to determine the length of the variable at compile time by the first assignment (if no explicit allocation exists, through LENGHT, INPUT or FORMAT), which on some cases may not be, correctly determined (see bellow).
If it fails, it will simply choose the default allocations size. 200 characters for alphanumeric vars and 8 bytes for numeric vars.
For example:
data _null_;
X1='XXX';
X2=substr('XXX',1,2);
X3=cats('XXX');
X4=repeat('X',int(ranuni(0)*10)+1);
L1=vlength(X1);
L2=vlength(X2);
L3=vlength(X3);
L4=vlength(X4);
put _all_;
run;
Returns:
X1=XXX X2=XX X3=XXX X4=XXXXXXXXXX L1=3 L2=3 L3=200 L4=200 _ERROR_=0 _N_=1
X1's size was correctly determined (3).
X2's size is somehow incorrect, the result of substr will produce a 2 char text, but instead, the length of the source expression (3) was choosen.
X3 and X4 were too complex, and therefore allocated with the default size (200).
Cheers from Portugal.
Daniel Santos @
www.cgd.pt.