Help using Base SAS procedures

reading data from xlsx file

Accepted Solution Solved
Reply
Super Contributor
Posts: 266
Accepted Solution

reading data from xlsx file

I copied a table from a pdf file that contained Exam Code and Exam Name and pasted it into Excel. The results were pasted into one column instead of two separate ones.  I want to read the data like so:

 

Data I want:

Exam_Code   Exam_Name

7                     United States History

13                   Art History

14                   Studio Art: Drawing Portfolio

.

.

.

 

Data I have in Excel. (I also pasted it into Notepad with similar results).

 

7
United States History
13
Art History
14
Studio Art: Drawing Portfolio
15
Studio Art: 2-D Design Portfolio
16
Studio Art: 3-D Design Portfolio

Accepted Solutions
Solution
‎04-21-2017 11:59 AM
PROC Star
Posts: 7,356

Re: reading data from xlsx file

@GreggB: Then why not just input it the same way, i.e.:

 

data want;
  informat Exam_Name $50.;
  input Exam_Code/  Exam_Name &;
  cards;
7
United States History
13
Art History
14
Studio Art: Drawing Portfolio
;

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Solution
‎04-21-2017 11:59 AM
PROC Star
Posts: 7,356

Re: reading data from xlsx file

@GreggB: Then why not just input it the same way, i.e.:

 

data want;
  informat Exam_Name $50.;
  input Exam_Code/  Exam_Name &;
  cards;
7
United States History
13
Art History
14
Studio Art: Drawing Portfolio
;

Art, CEO, AnalystFinder.com

Super User
Posts: 17,745

Re: reading data from xlsx file

If you have Adobe Professional it can convert the doc to Excel or Word and will save the formatting, at least better than copy and paste. 

 

If you don't have Adobe Professional, you can use the second file, the txt file and easily read that in using SAS. 

 

data want;

infile 'path to text file' truncover;

input number / name $20.;

run;

 

 

Super User
Posts: 10,463

Re: reading data from xlsx file

Not actually a SAS related question.

You likely need a PDF viewer/editor that has a "Copy TABLE" option to maintain the "columns" in the PDF table. If the PDF data is NOT a table then you're likely going to have a lot of work if you want the result in Excel.

 

Note that SAS can read that pasted text file (notepad) with a proper data step. Something like

data want;

   infile 'c:\path\filename.txt' truncover;

   informat exam_code best5. exam_name $50.;

   input exam_code

            /exam_name 1-50;

run;

Super Contributor
Posts: 266

Re: reading data from xlsx file

I don't want the result in Excel. I was just trying to think of a way to get SAS to read it. I should have pasted directly to the text editor.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 172 views
  • 2 likes
  • 4 in conversation