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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.