DATA Step, Macro, Functions and more

scan function

Reply
Occasional Contributor
Posts: 12

scan function

data test; 

x  =  'charles dickens' ;

y =scan (x ,2 ) ;

run;

 

length of scan function is said to be 200 , then why i am getting the length of y as 15 . substr function takes the length of input function is scan function also working like this ? please help . 

Respected Advisor
Posts: 3,288

Re: scan function

[ Edited ]

Please read the SAS 9.4 documentation at http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p0jshdjy2z9zdzn1h7k90u99lyq6.htm&...

 

which says 

 

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. This behavior is different from the behavior in previous releases of SAS. In previous releases, code that created a variable with a length of 200 might have produced a variable with a length that was greater than expected. If you need the SCAN function to assign a variable with a value that is different from the length of the first argument, use a LENGTH statement.

--
Paige Miller
Contributor VDD
Contributor
Posts: 27

Re: scan function

because Y takes the lenght of X since Y was not declared until you assigned Y to scan X

Contributor VDD
Contributor
Posts: 27

Re: scan function

data test; 

lenght y $200;

x  =  'charles dickens' ;

y =scan (x ,2 ) ;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 51 views
  • 3 likes
  • 3 in conversation