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

Hi.. I know there are many SQL experts here (obviously I'm not one). .. I'm trying to link 2 tables, one is a data warehouse on the server and the other is on my local machine.. How can I select only certain columns from the the server table. Here is the code I have:

 

rsubmit;
PROC SQL;
 connect to server(user=&user. password=&password. Mode=TTTTT 
 tdpid=ssss);

create table ABC.AAA_BBB (compress=yes reuse=yes) as
 select distinct a.*, b.*
 from ABC.AAA_DDD a join (Select * from connection to teradata    
    (select * from SDW001.STN_DLY)) b
 on b.ast_id = a.ast_id
 order by a.ast_id ;
quit;
endrsubmit;

SDW001 has 20 columns , 4 that are shared between ABC.AAA_DDD, but I only want all but 3 columns.. I want to drop the ones that are shared between ABC.AAA_DDD and SDW001

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your existing code probably actually does what you want.  When you use SELECT A.*,B.* and there are variables in the table referenced by B that also exist in the table referenced by A then SAS will not add them to the output dataset.

 

But the best solution is to list only the fields you need in the pass through SQL query.  This will make sure that you only move data that you need from the Teradata server to the SAS server.  You can query the SAS or Teradata metadata to get a list of the variables and just delete the three that you do not want.  If you are using Teradata's free SQL Assistant application it is easy to get the list by just right clicking on the table name and selecting browse.

 

For the DROP/KEEP approach, as @art297 said:

Both of the following work for me:

 

 

proc sql;
  create table want (drop=sex) as
    select *
      from sashelp.class
  ;
quit;


proc sql;
  create table want as
    select *
      from sashelp.class (drop=sex)
  ;

quit;

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

when you specify the tables in your from statement (e.g., from ABC, etc) you can use data set options like keep and drop.  e.g.:

from ABC (keep=this that something_else),BBB (drop=var6 var_whatever).

podarum
Quartz | Level 8

How would I specify (using my code as an example) that I don't want to include CAPTR_DT from the SDW001.STN_DLY table ?.. because I have tried wiht drop and keep in different areas of the code and nothing worked for me..

art297
Opal | Level 21

I don't have teradata, thus I can't test an example.

Both of the following work for me:

proc sql;

  create table want (drop=sex) as

    select *

      from sashelp.class

  ;

quit;

proc sql;

  create table want as

    select *

      from sashelp.class (drop=sex)

  ;

quit;

shivas
Pyrite | Level 9

Hi,

Select only the list of variable you want in the output table...for eg

instead of

select * from

try using

select col1,col2,col3

Thanks,

Shiva

Tom
Super User Tom
Super User

Your existing code probably actually does what you want.  When you use SELECT A.*,B.* and there are variables in the table referenced by B that also exist in the table referenced by A then SAS will not add them to the output dataset.

 

But the best solution is to list only the fields you need in the pass through SQL query.  This will make sure that you only move data that you need from the Teradata server to the SAS server.  You can query the SAS or Teradata metadata to get a list of the variables and just delete the three that you do not want.  If you are using Teradata's free SQL Assistant application it is easy to get the list by just right clicking on the table name and selecting browse.

 

For the DROP/KEEP approach, as @art297 said:

Both of the following work for me:

 

 

proc sql;
  create table want (drop=sex) as
    select *
      from sashelp.class
  ;
quit;


proc sql;
  create table want as
    select *
      from sashelp.class (drop=sex)
  ;

quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 82433 views
  • 4 likes
  • 4 in conversation