@SAS47 wrote:
Hello Everyone,
I am preparing for BASE SAS Specialist. A very common question in Dumps is to find the length of First Variable. I have coded in this SAS studio (Please Find the Code Below) and the length of the variable First is 200 but I am not able to find the reason for this.
Please Let me know why length of the variable first (in below code) would be 200?
data work.test;
Author= 'Agatha Christie';
First=substr(scan(author,1, ' '),1,1);
run;
Suggestion: Run that code and examine the result. Proc Contents is your friend when dealing with specific examples. Run the data step then contents and there's the answer.
It appears that perhaps your SAS studio is not following the latest documentation (or the results from SAS 9.4) as I get 15 not 200.
Author |
Char |
15 |
First |
Char |
15 |
The documentation for most, if not all, of the character manipulation functions will have a bit on what the default lengths are, and how they are assigned.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n0n08xougp40i5n1xw7njpcy0a2b.h...
for example.
Which says the variable would have the length of the first parameter.
So you look at SCAN to see how it sets length as the first parameter to SUBSTR is the result of SCAN function.
Which will use the length of it's first parameter, or that of Author.
From https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.h...
"In a DATA step, if the SCAN function returns a value to a variable that has not yet been given a length, that variable is given the length of the first argument."
There is a note about older versions of SAS set lengths of 200 for SCAN result, so be careful with older references. So perhaps your SAS Studio is connecting to something not running a recent release of SAS.
Don't know what "Dumps" is so can't comment on anything there.