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

Hi all. I'm looking to move a current Excel process into SAS, for convenience, however, I have an issue stemming from the fact the base data I have to work with is currently only available to me in Excel and will require importing.

 

One of my columns in Excel is a "date" column, written as YYYYMM (so, October 2015 would be 201510). This is stored in Excel under General format and not as a date, so when I import the sheet to SAS, it doesn't recognise that 201510 is supposed to be October 2015.

 

I do not have access to the base data itself (this is provided by a separate team) and would like to avoid having to manually alter the column every time it's received, if at all possible.

 

Is there a way I can import this, so SAS recognises the column as a list of dates, or so SAS converts the string to a format it can recognise as a date?

 

Any help is greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You only need a simple conversion step after import:

data have;
date = 201510;
run;

data want;
set have;
format date yymmn6.;
date = input(put(date,6.),yymmn6.);
run;

But you can read the date correctly if you save the spreadsheet to a csv file and read the column from that with the YYMMN6. informat.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

You only need a simple conversion step after import:

data have;
date = 201510;
run;

data want;
set have;
format date yymmn6.;
date = input(put(date,6.),yymmn6.);
run;

But you can read the date correctly if you save the spreadsheet to a csv file and read the column from that with the YYMMN6. informat.

AlexPanebianco
Calcite | Level 5
Excellent, thanks for this (and apologies for my slow response). I'll give this a try.
SASJedi
SAS Super FREQ

You could also read this in with a DATA step. If the column is formatted General with only digits in it:

SASJedi_0-1645016258215.png

it's probably being read into SAS as a numeric, and something like this would do the trick:

libname xl xlsx "c:\temp\have.xlsx";
data want;
   set xl.have;
   date=mdy(mod(DateAsNumber,100),1,int(DateAsNumber/100));
   format date mmddyy10.;
run;

Result:

DateAsNumber date
202201 01/01/2022
202202 02/01/2022
202203 03/01/2022
202204 04/01/2022
202205 05/01/2022
202206 06/01/2022
202207 07/01/2022
202208 08/01/2022
202209 09/01/2022
202210 10/01/2022
202211 11/01/2022
202212 12/01/2022


 

Check out my Jedi SAS Tricks for SAS Users

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
  • 3 replies
  • 3187 views
  • 4 likes
  • 3 in conversation