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

I have a sas file with 6210 rows with a column "date" formated as mm/dd/yyy (06/30/2002 for example) and I would like to convert it to a string that would read the date as yyyymmdd (20020630 for the date above). 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Use the YYMMDDN. format

 

data want;
    set have;
    format date yymmddn8.;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Use the YYMMDDN. format

 

data want;
    set have;
    format date yymmddn8.;
run;
--
Paige Miller
nmlynar13
Calcite | Level 5

Worked perfectly, thank you!

Tom
Super User Tom
Super User

@nmlynar13 wrote:

I have a sas file with 6210 rows with a column "date" formated as mm/dd/yyy (06/30/2002 for example) and I would like to convert it to a string that would read the date as yyyymmdd (20020630 for the date above). 


A SAS dataset has variables.  What does PROC CONTENTS say about how the DATE variable is defined?

 

If the variable is numeric with the MMDDYY10. format attached to it then you can just change the format attached to the variable to YYMMDDN8. to have it print the dates in that style. 

format date yymmddn8.;

If you want to create a new character variable that has strings that look like then use theYYMMDDN8. format with the PUT() function to generate the new variable.

newvar = put(date,yymmddn8.);

If the variable is character then use the MMDDYY10. informat to convert the values to dates and then use the YYMMDDN8. format to convert it back into a string in that style.

date = put(input(date,mmddyy10.),yymmddn8.);

And if you want to make a new numeric variable that stores dates as number like YY,YYM,MDD then why would you do that?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 480 views
  • 0 likes
  • 3 in conversation