BookmarkSubscribeRSS Feed
sanyam13
Fluorite | Level 6

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 . 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

data test; 

lenght y $200;

x  =  'charles dickens' ;

y =scan (x ,2 ) ;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 774 views
  • 3 likes
  • 3 in conversation