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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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