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

Hello Experts,

 

My data is  LB_DOSS that have the values, for example, 

blbla 21/07/2021

blabla 23/06/2009

 

I extract the data like  Date_prelevement=scan(LB_DOSS,-1); My results are : 

 

21/07/2021

23/06/2009

 

Do you know please the best way to convert the date (DD/MM/YYYY) from character to numeric values  ?

 

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

The SAS Docu for the SCAN() Function will tell you that this function allows for additional parameters of which one is for definition of the characters used as word separators.

Patrick_1-1646734829156.png

 

data want;
  infile datalines truncover;
  input LB_DOSS $40.;
  Date_prelevement=input(scan(LB_DOSS,-1,' '),ddmmyy10.);
  format date_prelevement date9.;
  datalines;
blbla 21/07/2021
blabla 23/06/2009
;

proc print data=want;
run;

Patrick_0-1646734664173.png

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Can you please explain how we can find, in general, the date information you want in this character string? Do we find the first space after blablabla and read the date? Can blablabla have its own space in it? Do we have to follow some other rules? If so, what are they? We need to know what rules will work here. We shouldn't have to guess ... you know what the rules are so tell us.

 

As I said in your other thread, you are strongly advised to present data in an accepted and useful format without us even asking. Do this automatically from now on please. No exceptions, no excuses.

 

We need to see a portion of data set DOSS2 provided according to these instructions. Many people just ignore the instructions when I mention it. Please do not provide the data in any other manner, as that won't help, and we'll just ask you to follow the instructions again.

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
Thank you for your message.
Sorry, I improved my question.
Tom
Super User Tom
Super User

The INPUT() function let's you use an INFORMAT to convert text into values.  So if you use the informat of DDMMYY it will be able to convert those string into date values.  You can then assign the values to a numeric variable and attach a format that works with date values to display them in a way that humans will understand.  I would avoid using DDMMYY or MMDDYY as the display format as either one will confuse half of your audience.  So use DATE or YYMMDD instead.

data want;
  set have;
  Date_prelevement=input(scan(LB_DOSS,-1),ddmmyy10.);
  format date_prelevement date9.;
run;
SASdevAnneMarie
Barite | Level 11
Hello Tom,

Finally, I do : Date_prelevement=scan(LB_DOSS,-3)||"/"||scan(LB_DOSS,-2)||"/"||scan(LB_DOSS,-1)
because when I do scan(LB_DOSS,-1) I have only the year. Do you know some option for scan function to avoid the "/" and get the date without scanning 3 times please ?

Thank you !
Patrick
Opal | Level 21

The SAS Docu for the SCAN() Function will tell you that this function allows for additional parameters of which one is for definition of the characters used as word separators.

Patrick_1-1646734829156.png

 

data want;
  infile datalines truncover;
  input LB_DOSS $40.;
  Date_prelevement=input(scan(LB_DOSS,-1,' '),ddmmyy10.);
  format date_prelevement date9.;
  datalines;
blbla 21/07/2021
blabla 23/06/2009
;

proc print data=want;
run;

Patrick_0-1646734664173.png

 

SASdevAnneMarie
Barite | Level 11
Thank you Patrick !

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 874 views
  • 3 likes
  • 4 in conversation