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

I am accessing an MS SQL Server database that contains tables and view with the same object names (i.e. FRED.TABLE and FRED.VIEW both exist in the schema), but the tables and views folders.  I know that the views are better curated for querying in SAS but I suspect that the LIBNAME statement is accessing the tables and not the views.  Is there a way to point to the views in a MS SQL Server database and not the tables in SAS SQL or a DATA step?

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

I haven't tried it but you should be able to specify the VIEW extension in SQL Passthru:

select * from [MySQLServer].[MyDatabase].[MySchema].[MyTable].[VIEW]

 

It is common practice to actually name views like so: vw_MyTable rather than have exactly the same names in my experience.

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

I haven't tried it but you should be able to specify the VIEW extension in SQL Passthru:

select * from [MySQLServer].[MyDatabase].[MySchema].[MyTable].[VIEW]

 

It is common practice to actually name views like so: vw_MyTable rather than have exactly the same names in my experience.

Jim_Cooper_hmsa
Obsidian | Level 7

Thank you for your response.  You solution matches what I expected to see.  I agree that normally views would be named to differentiate them from tables, but analysts in the business were not consulted when the database was architected.  I can point directly to the views using pass through queries, but then I am dependent on another IDE to explore the tables.  It is more convenient to use Libname statements in EG or SAS Studio so that the table structures are visible in the Library pane.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 1407 views
  • 1 like
  • 2 in conversation