BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_student1
Quartz | Level 8

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!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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

sas_student1
Quartz | Level 8

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

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

 

Thank you!

AndrewHowell
Moderator

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:

 

sas_student1
Quartz | Level 8

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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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