- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to figure out how to connect SAS to a query that is developed in MS access.
There is query in Access that uses a combination of tables and other queries to create a query that I need.
Now I was I found this site (https://heuristically.wordpress.com/2010/06/04/sql-sas-access-2007-accdb/) that shows me how to connect SAS to a table in MS access which worked.
But how does one connect to a query in MS access?
Suggestions? links to articles that would help guide me?
Thank you in advance!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the approach in the referenced site worked for you to connect to a table then did you try replacing the name of the example table with the name of your query?
If the query is typical you may need put the name in quotes to handle long names with spaces and possibly set the VALIDMEMNAME=EXTEND option
You may need to set the option VALIDVARNAME=ANY to get SAS to accept any spaces or odd characters in the query variable names.
Code to use those names in SAS would then look like "Month total"n (since space is not normally accepted as a variable name the Access variable/column name would need quotes and the n immediately following tells SAS to treat as variable name.
Also if you have SAS/Access Interface to PC Files you may be able to get to the data with a libname statement.
Which would look like
Libname yourlib "C:\pathtoaccessdatabase\MyDatabase.accdb";
or
Libname yourlib ACCESS Path= "C:\pathtoaccessdatabase\MyDatabase.accdb";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If the approach in the referenced site worked for you to connect to a table then did you try replacing the name of the example table with the name of your query?
If the query is typical you may need put the name in quotes to handle long names with spaces and possibly set the VALIDMEMNAME=EXTEND option
You may need to set the option VALIDVARNAME=ANY to get SAS to accept any spaces or odd characters in the query variable names.
Code to use those names in SAS would then look like "Month total"n (since space is not normally accepted as a variable name the Access variable/column name would need quotes and the n immediately following tells SAS to treat as variable name.
Also if you have SAS/Access Interface to PC Files you may be able to get to the data with a libname statement.
Which would look like
Libname yourlib "C:\pathtoaccessdatabase\MyDatabase.accdb";
or
Libname yourlib ACCESS Path= "C:\pathtoaccessdatabase\MyDatabase.accdb";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
OMG!! *face palm* a simple libname worked!!
it connected to the query in access and yielded the table I needed.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok, breaking it down & seeking clarification:
- You want to access a Microsoft Access database. What version of SAS and/or Access products do you have?
- You want to execute an in-database query - that's an explicit SQL "execute" command.
- Your statement: "There is query in Access that uses a combination of tables and other queries to create a query" - a query which creates a query, are you sure? I would have expected a query which creates/updates a table.
Depending on your product set and/or version, suggest you look at:
- SAS/ACCESS® 9.4 Interface to PC Files: Reference, Fourth Edition (if connecting via MS-Access)
- SAS/ACCESS® 9.4 for Relational Databases: Reference, Ninth Edition (if connecting via ODBC)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your comment.
A simple libname worked and got what I needed.
To your question in 3, yes I am sure, I "inherited" this database in access and making heads and tails of it. I opened up one of the query in design view and was surprised to see that this one query was calling another query in and connecting to a table.
But the libname to access the query in SAS and creating a table that I needed worked!
Thanks for your assistance. The links were very useful and I will keep this as my reference.