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

Please  help me solve the question below. I appreciate your help.

 

Which assignment statement extracts 2019 from the Text variable?

 

1 data Scan_Quiz;
2 Text="New Year's Day, January 1st, 2019";
3 run;
4

 

A. 1 Year=scan(Text, 6);

B. 1 Year=scan(Text, 6, ', ');

 

I know A is correct but I don't understand why B is correct too?

Under B, Test will be divided by 3 

New Year's Day          and           January 1st           and              2019

because  ', ' has one comma and one space. Therefore I assumed B should be like below,

B. 1 Year=scan(Text, 3, ', ');

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @TokyoSAS 

 

It is correct because there is a space after the comma in the specified delimiter, though it is difficult to see:

 Year=scan(Text, 6, ', ');

 Year=scan(Text, 6, ',');

 

Scan searches for any of the specified delimiters, so the string is split:  "New | Year's | Day, |January | 1st, | 2019

 

Now you probably ask why the commas don't seem to count. They do, but both of the commas are followed by a space, and the default behaviour of scan is to consider two or more consecutive delimiters as one, so the spaces following the commas don't count.

 

 

 

 

View solution in original post

2 REPLIES 2
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @TokyoSAS 

 

It is correct because there is a space after the comma in the specified delimiter, though it is difficult to see:

 Year=scan(Text, 6, ', ');

 Year=scan(Text, 6, ',');

 

Scan searches for any of the specified delimiters, so the string is split:  "New | Year's | Day, |January | 1st, | 2019

 

Now you probably ask why the commas don't seem to count. They do, but both of the commas are followed by a space, and the default behaviour of scan is to consider two or more consecutive delimiters as one, so the spaces following the commas don't count.

 

 

 

 

LinusH
Tourmaline | Level 20
The space make that as valid separate delimiter as well, it's not the combination that is the delimiter.
Data never sleeps

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 503 views
  • 1 like
  • 3 in conversation