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, ', ');
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.