BookmarkSubscribeRSS Feed
Agha
Calcite | Level 5

dates

2013-08-13,2013-10-18,2013-12-16,2014-03-07,2014-04-30,2014-06-11,2014-07-24,2014-08-11,2014-09-29,2014-11-24,2015-05-05,2015-08-19,2015-10-19,2016-04-15,2016-06-28,2016-10-28,2017-02-13,2017-11-06

2020-09-25,2020-10-27,2020-12-08,2021-02-02,2021-04-13,2021-06-08,2022-05-06,2022-07-26,2023-02-28

2022-06-27,2022-08-23,2022-11-07,2022-12-13,2023-01-24

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Let me speak from experience, you will be better off if you have all the dates in one column, rather than separate columns. Many times people choose a poor layout for the data, and wind up causing later programming difficulties. So, a word to the wise, put the dates in a single column.


This code assumes your data is in a SAS data set named HAVE.

 

data want;
    set have;
    seq=_n_;
    do i=1 to countw(dates,',');
         date=input(scan(dates,i,','),yymmdd10.);
         output;
    end;
    format date yymmdd10.;
    drop i dates;
run;

 

 

--
Paige Miller
Astounding
PROC Star

Agree with the advice.  A small tweak to the solution:

 do i=1 to 1 + countw(dates,',');

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 890 views
  • 2 likes
  • 3 in conversation