DATA Step, Macro, Functions and more

How to connect SAS to MS Access query

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

How to connect SAS to MS Access query

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
Solution
3 weeks ago
Super User
Posts: 12,996

Re: How to connect SAS to MS Access query

Posted in reply to sas_student1

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";

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 12,996

Re: How to connect SAS to MS Access query

Posted in reply to sas_student1

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";

Contributor
Posts: 43

Re: How to connect SAS to MS Access query

OMG!! *face palm* a simple libname worked!!

it connected to the query in access and yielded the table I needed.

 

Thank you!

Moderator
Posts: 310

Re: How to connect SAS to MS Access query

Posted in reply to sas_student1

Ok, breaking it down & seeking clarification:

 

  1. You want to access a Microsoft Access database. What version of SAS and/or Access products do you have?
  2. You want to execute an in-database query - that's an explicit SQL "execute" command.
  3. 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:

 

Contributor
Posts: 43

Re: How to connect SAS to MS Access query

Posted in reply to AndrewHowell

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.

 

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 110 views
  • 1 like
  • 3 in conversation