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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 17896 views
  • 1 like
  • 3 in conversation