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

I have some oddly formatted data from an excel spread sheet I'm trying to read in. A sample of the excel file I'm trying to read in is below. So in particular there are two challenges. I would like to ignore the title and start reading in and get names from the top header: Date, A, B, C, D, E, F, Time/Date. This is an sample of the spread sheet:

TITLE
DateABCDEFTime
Date
January
1/20/2004Company A2:00 p.m.ConnecticutNA4,000400,001/26/04, 9:00 a.m.
February
2/12/2004Company B11:32 a.m.San FranciscoNA1,000 340,0003/01/04, 8:50 a.m.
2/28/2004CompanyC 1:00 pm New York NA NA NA
None

The Date column is particularly tricky for me because it has January and February, etc followed by MM/DD/YYYY format beneath it. How can I just read in the MM/DD/YYYY, and ignore the January, February, March, etc or place it side by side while reading in such as  January 1/20/2004, in separate columns, and then the same for February, etc. So When reading in I would like to see something like

MonthDateABCDEFTime/Date
January1/20/2004Company A2:00 p.m.ConnecticutNA4,000400,001/26/04, 9:00 a.m.
February2/12/2004Company B11:32 a.m.San FranciscoNA1,000 340,0003/01/04, 8:50 a.m.
February 2/28/2004CompanyC 1:00 pm New York NA NA NA

Any suggestions?

I'm using this code to begin reading the file in:

PROC IMPORT OUT= WORK.Out

            DATAFILE= "C:\Users\Desktop\Data\Excel1.xls"

            DBMS=EXCEL REPLACE;

     RANGE="Sheet1$";

     GETNAMES=YES;

     MIXED=NO;

     SCANTEXT=YES;

     USEDATE=YES;

     SCANTIME=YES;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I don't think there's an easy way in any language Smiley Happy

There are ways though..

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

Reading Excel files like this is like reading reports.

The best option if available is to try to get a more clean layout from your source (this is to done on a regular basis right?, otherwise fix the Excel manually first).

Is the month name in a separate cell/row?

Either way, import, and then do some data step programming to fix it in the way you like it.

Data never sleeps
steppermotor
Calcite | Level 5

Yeah, I don't mind fixing the excel manually except. I have a several files that I would have to do so, it seems being able to read in the native format with sas would be the best strategy. The Time and Date are in a separate cell/row.

Reeza
Super User

Is the data the exact same in each file, ie same row/same column? If so you could do it "manually" once using DDE and then run for each file.

Still a pain though.

steppermotor
Calcite | Level 5

So I guess there's no easy ways to do this in sas?

Reeza
Super User

I don't think there's an easy way in any language Smiley Happy

There are ways though..

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 848 views
  • 0 likes
  • 3 in conversation