BookmarkSubscribeRSS Feed
JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

Date for example: 3/21/2021, 

want to convert to 2021/3/21, 

 

Is there as good way to do instead convert to Str  ...? 

Does SAS has date format as yyyy/mm/dd ?

 

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@JHE wrote:

Date for example: 3/21/2021, 

want to convert to 2021/3/21, 

 

Is there as good way to do instead convert to Str  ...? 

Does SAS has date format as yyyy/mm/dd ?

just assign a different format to this variable.

 

You want

 

format variablename yymmdds10.;

 

in a DATA step or PROC

--
Paige Miller
ballardw
Super User

SAS has a LOT of date, time and datetime formats plus you can roll your own. However you want to start with an actual SAS date value.

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

 

If you already have date value then you just assign the format you want with a Format statement such as

 

Format datevariable yymmdd10.;

 

One of the very nice things about formats is that you can specify the format to use just about anytime you need to and are not stuck with a default set.

 

Example for creating a date value and then displaying it in Proc print with different formats:

data example;
   date ='21Mar2021'd;
   format date date9.;
run;
/* this uses whatever the default format may be*/
Proc print data=example noobs;
run;

Proc print data=example;
   format date yymmdd10.;
run;

Proc print data=example;
   format date worddate.;
run;

/* Julian date: year and then day of the year*/
Proc print data=example;
   format date juldate.;
run;

I suggest keeping track of https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/leforinforref/n0p2fmevfgj470n17h4k9f27qjag.ht...

so you can look up the SAS formats and informats by type easily.

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

thank you.

 

But need result as: YYYY/MM/DD, such as 2021/02/23

 

Cynthia_sas
SAS Super FREQ

Hi:

  There is a way in the yymmdd format to specify what type of separator you want. Here's an example that shows the BIRTHDAY variable being read into a SAS numeric variable that represents a date. Then the year the person turns 21 and the year they turn 65 are calculated using the INTNX function to create 2 new variables. The date variables are each displayed using a different format for display:

Cynthia_sas_0-1629837873719.png

 

 

Cynthia

JHE
Obsidian | Level 7 JHE
Obsidian | Level 7

I go it, YYYMMDDSD10.

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
  • 6 replies
  • 1080 views
  • 0 likes
  • 5 in conversation