Hi All,
I am trying to get the month or the following dates. The problem is when I use scan(dt,2) and if there is no value between 2 delimiter, it will be skipped. Also, there is no means to know what is the delimiter. Could you please advise how can I get '2021//03' as year 2021 month missing and day 03?
Here are my testing code:
data yymmdd_de; infile datalines delimiter=','; input dt $50.; datalines; 21 03 14 21/03/14 21-03 21//03 21 03 ; data test; set yymmdd_de; m=scan(dt,2); run;
Here is the result:
Many thanks in advance!
data test;
set yymmdd_de;
m=scan(dt,2, "/- ", 'm');
run;
m or M | specifies that multiple consecutive delimiters, and delimiters at the beginning or end of the string argument, refer to words that have a length of zero. If the M modifier is not specified, then multiple consecutive delimiters are treated as one delimiter, and delimiters at the beginning or end of the string argument are ignored. |
data test;
set yymmdd_de;
m=scan(dt,2, "/- ", 'm');
run;
m or M | specifies that multiple consecutive delimiters, and delimiters at the beginning or end of the string argument, refer to words that have a length of zero. If the M modifier is not specified, then multiple consecutive delimiters are treated as one delimiter, and delimiters at the beginning or end of the string argument are ignored. |
Appreciate your response, it solve my problem. Thank you
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!
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.