@ab12nov wrote:
Hi,
Below is the program:
data work.test;
Author = 'Agatha Christie';
First = substr(scan(author,1,' ,'),1,1);
run;
Can you tell me why the length of first is returned as 200 even when author has 15....??
Because SAS cannot read your mind, although SAS 9.4 seems to know that 15 is the max that function will generate.
Note that there are functions like FIRST() and CHAR() that SAS knows will only return one character.
But if you want FIRST to be one character long then define it that way. And if you did define it that way then you don't really need SUBSTR() function anymore.
data test;
Author = 'Agatha Christie';
First1 = substr(scan(author,1,' ,'),1,1);
First2 = first(scan(author,1,' ,'));
First3 = char(scan(author,1,' ,'),1);
length first $1 ;
first= scan(author,1,' ,') ;
run;
proc contents; run;
proc print; run;
... View more