Solved

How to read a dataset of files in SAS

Posted on 2011-02-14
5
1,377 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now