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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

You need to use the informat MONYY.

 

You can't use DDMMYY10. because no days are provided in the input data.

--
Paige Miller
Anita_n
Pyrite | Level 9

I tried that now and is given me this warning

invalid data for datvar in line 509 1-5

PaigeMiller
Diamond | Level 26

It worked for me with English month names.

 

I see @Kurt_Bremser has a good solution.

--
Paige Miller
Kurt_Bremser
Super User

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

Anita_n
Pyrite | Level 9

Is there any way to control the output of the date as 01.02.2001 or 01-02-2001?

Anita_n
Pyrite | Level 9

thank you, it worked

I appreciate that

 

Anita_n
Pyrite | Level 9

okay thanks a lot

Tom
Super User Tom
Super User

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
;
Anita_n
Pyrite | Level 9

that works also. Thanks

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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