BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tinaz5012
Obsidian | Level 7

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:

scan.jpg

 

Many thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data test;
set yymmdd_de;
m=scan(dt,2, "/- ", 'm');
run;

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.h...

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.

View solution in original post

2 REPLIES 2
Reeza
Super User
data test;
set yymmdd_de;
m=scan(dt,2, "/- ", 'm');
run;

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.h...

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.
tinaz5012
Obsidian | Level 7

Appreciate your response, it solve my problem. Thank you

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1387 views
  • 1 like
  • 2 in conversation