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

Hello,

I have character date  01/29/2019 (format $10, informat $10). I want to convert it into 2019-01-29. I searched online and tried different ways, but still not successful.  

please help.

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@superbug wrote:

Hello,

I have character date  01/29/2019 (format $10, informat $10). I want to convert it into 2019-01-29. I searched online and tried different ways, but still not successful.  

please help.

thanks!


Do you want to create an actual date variable?

date_var=input(char_var,mmddyy10.);
format date_var yymmdd10.;

Or another character variable?

char_var2=put(input(char_var,mmddyy10.),yymmdd10.);

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

@superbug wrote:

Hello,

I have character date  01/29/2019 (format $10, informat $10). I want to convert it into 2019-01-29. I searched online and tried different ways, but still not successful.  

please help.

thanks!


Do you want to create an actual date variable?

date_var=input(char_var,mmddyy10.);
format date_var yymmdd10.;

Or another character variable?

char_var2=put(input(char_var,mmddyy10.),yymmdd10.);
superbug
Quartz | Level 8

@Tom 

I want another character variable. 

you code worked!

Thanks much!

Cynthia_sas
SAS Super FREQ

Hi:

  You need to create a new numeric variable using the INPUT function, as shown below:

convert_char_date.png

In the above program, the variable CDATE is the character date from the input data. The variable BIRTHDAY is the numeric value that is the result of using the INPUT function on CDATE with the mmddyy10. informat. The INPUT function returns the value of the date as the number of days since Jan 1, 1960, which is how SAS date values are stored. The variables BDAY1 and BDAY2 are just copies of the BIRTHDAY variable so a different format can be applied.

 

In the PROC PRINT, there's no format applied to BIRTHDAY, so you can see how the value for the date is stored internally. Then, BDAY1 is formatted with the yymmdd10. format and BDAY2 is formatted with the worddate. format. The benefit of storing a date value as an offset from Jan 1 1960 is that the same number can use different formats to display the date however you wish.

 

Hope this helps,

cynthia

superbug
Quartz | Level 8

@Cynthia_sas 

Thanks much for you help!

your code also worked!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 22381 views
  • 1 like
  • 3 in conversation