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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 738 views
  • 1 like
  • 2 in conversation