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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 561 views
  • 1 like
  • 3 in conversation