SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
aanan1417
Quartz | Level 8

data have;

input date $10.;

datalines;

6-Mar-22

;

run;

 

data want;

input date $10.;

datalines;

06Mar2022

;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You never (as in NEVER) want to store dates or times as character, as you can't work with them. Read and store them as SAS date and time values in the first place.

data want;
input date :date9.;
format date yymmdd10.; /* use any date format which suits you here */
datalines;
6-Mar-22
;

Dates are counts of days, starting with 1960-01-01 as day zero, going back to 1582 (the introduction of the Gregorian calendar) and forward to at least 9999-12-31.

Times are counts of seconds, starting at midnight, or 1960-012-01T00:00:00 for datetimes.

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

You never (as in NEVER) want to store dates or times as character, as you can't work with them. Read and store them as SAS date and time values in the first place.

data want;
input date :date9.;
format date yymmdd10.; /* use any date format which suits you here */
datalines;
6-Mar-22
;

Dates are counts of days, starting with 1960-01-01 as day zero, going back to 1582 (the introduction of the Gregorian calendar) and forward to at least 9999-12-31.

Times are counts of seconds, starting at midnight, or 1960-012-01T00:00:00 for datetimes.

 

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!

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
  • 1 reply
  • 595 views
  • 0 likes
  • 2 in conversation