BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PrinceAde
Obsidian | Level 7

Hi everyone.

Please I need clarification on this;

In sas documentation here, https://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001336080.htm

 

It says; The default length of a target variable where the expression contains the SCAN function is 200 bytes.

Then under the sub heading "saving storage space", it reads; The SCAN function causes SAS to assign a length of 200 bytes to the target variable in an assignment statement. Most of the other character functions cause the target to have the same length as the original value.

When I tried the logic in sas 9.4 version, the latter is true i.e. the target variable in the scan function gave the same length as the first argument.

Given this mcq question I saw online;

data work.test;
Author = 'Agatha Christie';
First = substr(scan(author,1,' ,'),1,1);
run;

There were options for 15 and 200.

Please can you help to clarify this, I'm preparing for the sas base certification exam.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
Anytime you use SCAN in a WHERE statement, WHERE dataset option or SQL WHERE clause, the result is limited to 200 characters. If the substring extracted by the function exceeds 200 characters, it will be truncated.
This happens because a WHERE is always handled by SQL in the background.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Maxim 1: Read the Documentation.

From SCAN Function :

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.

PrinceAde
Obsidian | Level 7

from the documentation;

"If you use the SCAN function in an expression that contains operators or other functions, a word that is returned by the SCAN function can have a length of up to 32,767 characters, except in a WHERE clause. In that case, the maximum length is 200 characters."

Please can you illustrate scan function in a "where clause" where the target variable return the the maximum length is 200?

 

Thanks.

Kurt_Bremser
Super User
Anytime you use SCAN in a WHERE statement, WHERE dataset option or SQL WHERE clause, the result is limited to 200 characters. If the substring extracted by the function exceeds 200 characters, it will be truncated.
This happens because a WHERE is always handled by SQL in the background.
PrinceAde
Obsidian | Level 7

Thank you, I get it now @Kurt_Bremser 

Welcome to the Certification Community

 

This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:

Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers

 

Why Get SAS Certified.jpg

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
  • 4 replies
  • 861 views
  • 0 likes
  • 2 in conversation