New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
femiajumobi1
Quartz | Level 8

I am trying to format the date in a dataset.

 

 examples in the column for date are: 21658, 31193

I have used different approaches (e.g., date9., MMDDYY10. ) but unable to format the date

Please advise. The date appears as such using proc contents:

#

Variable

Type

Len

Format

Informat

Label

2

birth_date

Char

25

$25.

$25.

birth_date

 
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Variable birth_date is a character variable.  Dates in SAS must be numeric. You have to create a numeric variable with that value and then format the numeric variable. In this case, the values like 21658 and 31193 may be recognizable by SAS as dates, or they may have come over from Excel in which case additional manipulation is needed.

 

data want;
    set have;
    num_birth_date=input(birth_date,12.);
    format num_birth_date mmddyy10.;
run;

 

Side issue: if at all possible, avoid storing dates as characters. Store them in numeric SAS variables, in a form that SAS will recognize, which is the number of days since 01JAN1960, formatted however you want.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Variable birth_date is a character variable.  Dates in SAS must be numeric. You have to create a numeric variable with that value and then format the numeric variable. In this case, the values like 21658 and 31193 may be recognizable by SAS as dates, or they may have come over from Excel in which case additional manipulation is needed.

 

data want;
    set have;
    num_birth_date=input(birth_date,12.);
    format num_birth_date mmddyy10.;
run;

 

Side issue: if at all possible, avoid storing dates as characters. Store them in numeric SAS variables, in a form that SAS will recognize, which is the number of days since 01JAN1960, formatted however you want.

--
Paige Miller
femiajumobi1
Quartz | Level 8
Thanks @PaigeMiller

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!

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
  • 2 replies
  • 3986 views
  • 0 likes
  • 2 in conversation