BookmarkSubscribeRSS Feed
biotelemetry
Calcite | Level 5

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

3 REPLIES 3
Shmuel
Garnet | Level 18

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

ballardw
Super User

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.

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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