Solved

How to read a dataset of files in SAS

Posted on 2011-02-14
5
1,401 Views
Last Modified: 2013-11-16
Is there a way for SAS 9.1.3 to read through a folder of Excel files (regardless of Excel version whether Excel 5, Excel 2000, Excel 97, Excel 2003 etc.) to extract information only from a specific tab and save it in a SAS dataset?
0
Comment
Question by:mikecharters
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 250 total points
ID: 34894244
first step is to list the contents of the directory into a text file, then read that text file into a sas dataset
you may refer to http://www2.sas.com/proceedings/sugi23/Coders/p82.pdf for some sample

after that, read the contents of the dataset (which will have a lot of things, but most importantly, the filename) into macro variables. you can do this using a data _null_ step and call symput command.

with that, all you are left with is a do loop which loops from 1 to the number of rows in that dataset, and within that loop, do a PROC IMPORT. This assumes the worksheet name to be extracted stays the same for all the files, or some consistent way of identifying the worksheet to be extracted.
0
 

Assisted Solution

by:zuhairpk
zuhairpk earned 250 total points
ID: 34894285
I believe you can accomplish what you want by going throught the follwoing two articles
for getting list of files in folder:
http://support.sas.com/kb/24/820.html
for processing excel files after specifying the sheet name you want
http://www2.sas.com/proceedings/forum2007/119-2007.pdf
hope it helps
0
 

Author Comment

by:mikecharters
ID: 34923557
0
 

Author Comment

by:mikecharters
ID: 34923583
This comment was meant for previous comment but it saved before I expected.

The code above Read.txt is being used to read the Excel files within a folder however I thought it only worked if the files are saved in Excel 5 format (not sure given message below).  

I want to be able to avoid having to convert the files to Excel 5 first and just simply READ the Excel files are they currently exist, which may be in either Excel 5, 97, 2000 or whatever format (but definitely not later than 2003).

Ultimately I only want to be able to read just ONE tab on each Excel file.  In this tab, the variable names themselves are variables with values next to them.  That's not so relevent it's more just getting the the program to simply accept reading the Excel files in the first place and not crash with message:

ERROR: Database error. Examine fields and/or messages below.
Password protected files/cells are not supported.
ERROR: Database table must be entered first

Is there an Unprotect statement that I can add?

Thank you!




0
 

Author Comment

by:mikecharters
ID: 34923689
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Process mapping 5 67
Mongo DB 18 69
Is it safe to dump postgresql database that is in production? 3 58
Import text from rows into columns? 12 75
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question