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 !
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.
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;
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.
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;
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.
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.