DATA Step, Macro, Functions and more

format date

Reply
New User
Posts: 1

format date

Good Afternoon,

 

I have the following date format mm.yyyy (e.g 08.1960) and I need to put into the format of yyyy-mm (e.g 08-1960).  I have already done the following :

 

DATA TEST1c;

SET TEST1B;

DOB= INPUT (DOB, $8.);

FORMAT DOB yymmd.;

RUN;

 

It does not seem to be working. Any help is appreciated.

 

Thank you

Trusted Advisor
Posts: 1,369

Re: format date

Your question is similar to the next post. See solution there:

 

https://communities.sas.com/t5/Base-SAS-Programming/Informat-for-date-in-the-form-MM-YYYY/m-p/326564

Super User
Posts: 10,483

Re: format date

You should describe how something "is not working". Error? Post log and error message No output? Post log and any warnings or messages Unexpected output? Post input data and expected output.

 

Very likely your DOB variabe is numeric. You cannot have a character and numeric variable in a dataset with the same name which you attempted with the INPUT and a $ informat. Also Format with a datetype format is only going to work with a numeric value and will only make sense if the variable were read correctly. FORMATS control how the value is displayed, it does not change the actual content.

Super User
Posts: 5,080

Re: format date

If you have a character string "08.1960" that you want to change to "08-1960" that is pretty easy:

 

dob = translate(dob, '-', '.');

 

However:

 

  • What you have is not clear.  Is DOB actually a date, or is it a character string?
  • What you want is not clear.  The "08-1960" is not a match for "yyyy-mm"

You might start by running PROC CONTENTS on your data set and describing the results for DOB.

Ask a Question
Discussion stats
  • 3 replies
  • 125 views
  • 0 likes
  • 4 in conversation