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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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