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

Hi,

I have a date variable that is numeric ((02JAN2018) ) with date9. format and date 9 informat  length 8.

I would like it to be character date yymmdd10.

 

Your help will be appreciated

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

There is no such thing as a character date in SAS. You can convert the date to a plain old character string, which is only useful in labels and titles and reports. If you care going to do additional computations or work with the date, you need to leave it as numeric.

 

Here is the conversion to character:

 

char_date = put(date,yymmdd10.);

Perhaps you meant that you want to leave the variable as numeric but with a different format? That would be much more useful and reasonable than creating a character string. In that case, just change the format. 

 

Editor's note: 
As PaigeMiller noted, converting the date to a character string is different than reformatting the date with a format that uses characters.  If reformatting is the goal, Astounding provides example code that can be used in a Proc step or a DATA step.

format datevar yymmdd10.;

 

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

There is no such thing as a character date in SAS. You can convert the date to a plain old character string, which is only useful in labels and titles and reports. If you care going to do additional computations or work with the date, you need to leave it as numeric.

 

Here is the conversion to character:

 

char_date = put(date,yymmdd10.);

Perhaps you meant that you want to leave the variable as numeric but with a different format? That would be much more useful and reasonable than creating a character string. In that case, just change the format. 

 

Editor's note: 
As PaigeMiller noted, converting the date to a character string is different than reformatting the date with a format that uses characters.  If reformatting is the goal, Astounding provides example code that can be used in a Proc step or a DATA step.

format datevar yymmdd10.;

 

--
Paige Miller
Dhana18
Obsidian | Level 7

Thank you for your response, i would like to create a new character variable with yymmdd10. format.

Dhana18
Obsidian | Level 7

Thank you! I just changed the format and it worked!

PeterClemmensen
Tourmaline | Level 20
data test;   
   Date='02JAN2018'd;
   CharDate=put(Date, yymmdd10.);
   format Date date9.;
run;

However, not a good idea to have dates stored as character...

Astounding
PROC Star

If you are not happy with the DATE9 format, just use a different format:

 

format datevar yymmdd10.;

 

You can add that statement in a PROC step, in which case the format is used just for the duration of the procedure.

 

Or you can add it in a DATA step, in which case the format becomes the default format going forward from that point.

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