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!
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";
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";
OMG!! *face palm* a simple libname worked!!
it connected to the query in access and yielded the table I needed.
Thank you!
Ok, breaking it down & seeking clarification:
Depending on your product set and/or version, suggest you look at:
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.