Hi;
Just imagine, if you use the same variable 3 times conditionally say for eg in if-then-else construct.
if a>100 then length='Long';
else if 50<=a<=100 then length='Normal';
else if a<50 then length='short';
During compilation, the first instance the variable 'length' above is coupled with the value 'Long' which is only 4 bytes long. This is the case which you are confused of.
In the second case, even if the same variable is assigned with value 'Normal', which is 6 bytes long, it cannot be accommodated, means its get truncated to 4 char length.
So, the first value which is 4 char is determined as the variable's length for later use!
To avoid such truncations, SAS have LENGTH statement which you should use well before you actually use the variables in your statements like a declaration. You need to find the space needed for the longest value of the variable and then assign this number to that. So that there is no truncation happens like I said before. Hope this helps!
LENGTH length $ 6;
if a>100 then length='Long';
else if 50<=a<=100 then length='Normal';
else if a<50 then length='short'; /* Now its perfect*/
Cheers!
Jojan.
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.