Hello all,
I have a problem. I need to convert a set of character variables to date but it is not working
data test;
input datevar ddmmyy10.;
datalines;
Feb 2001
Mai 2010
Okt 2000
Dez 1998
;
run;
pls note that this is the german abbreviation for the months.
I want the to give me something like 01.02,2001 and so on.
pls I will appreciate any help
monyy won't recognize the German month abbreviations, and I found no suitable informat in the National Language Support section of the documentation.
I would roll me a custom informat for the months,and then use the mdy() function:
proc format;
invalue mon_deu
'Jan' = 1
'Feb' = 2
'Mär' = 3
'Apr' = 4
'Mai' = 5
'Jun' = 6
'Jul' = 7
'Aug' = 8
'Sep' = 9
'Okt' = 10
'Nov' = 11
'Dez' = 12
;
run;
data test;
input _datevar $8.;
datevar = mdy(input(substr(_datevar,1,3),mon_deu.),1,input(scan(_datevar,2),4.));
format datevar yymmddd10.;
datalines;
Feb 2001
Mai 2010
Okt 2000
Dez 1998
;
The "universal" informat anydtdte catches some of the months, but not all ("Mär","Mai","Okt","Dez" would fail).
You need to use the informat MONYY.
You can't use DDMMYY10. because no days are provided in the input data.
I tried that now and is given me this warning
invalid data for datvar in line 509 1-5
monyy won't recognize the German month abbreviations, and I found no suitable informat in the National Language Support section of the documentation.
I would roll me a custom informat for the months,and then use the mdy() function:
proc format;
invalue mon_deu
'Jan' = 1
'Feb' = 2
'Mär' = 3
'Apr' = 4
'Mai' = 5
'Jun' = 6
'Jul' = 7
'Aug' = 8
'Sep' = 9
'Okt' = 10
'Nov' = 11
'Dez' = 12
;
run;
data test;
input _datevar $8.;
datevar = mdy(input(substr(_datevar,1,3),mon_deu.),1,input(scan(_datevar,2),4.));
format datevar yymmddd10.;
datalines;
Feb 2001
Mai 2010
Okt 2000
Dez 1998
;
The "universal" informat anydtdte catches some of the months, but not all ("Mär","Mai","Okt","Dez" would fail).
Is there any way to control the output of the date as 01.02.2001 or 01-02-2001?
Yes. Use the ddmmyy10. (or ddmmyyp10. to get periods) display format.
thank you, it worked
I appreciate that
okay thanks a lot
The NLDATE informat should work. You just need to add a day number in the front.
data test;
input datestr $8. ;
datevar=input('01 ' || datestr, nldate11.);
format datevar yymmdd10. ;
datalines;
Feb 2001
Mai 2010
Okt 2000
Dez 1998
;
that works also. Thanks
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: