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

Hi SAS users,

 

Are there any automatic variables like SQLOBS for counting the number of observations from pass through SQL ?

 

SQLOBS worked for me for SAS Proc SQL's , but not Pass through.

 

In my code I have count the extraction for each iterations and load those counts into Oracle table for statistics.

 

Thanks,

Ana

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

So you aren't trying to count activity done inside of the remote database.  You are just waiting too long to capture the value of SQLOBS.  You have to get it before SQL runs another statement.

PROC SQL;
CONNECT TO ORACLE(PATH="&DB." USER=&ID. ORAPW=&Password.);
CREATE TABLE dataset AS SELECT * FROM CONNECTION TO ORACLE
( SELECT
......
);
%let COUNT1=&SQLOBS;
disconnect from Oracle;
quit;

%put &=COUNT1; 

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

What does your SQL look like? It is only populated with a row count if you create a SAS table.

SASAna
Quartz | Level 8
@SASKiwi

Its Oracle connecting pass through SQL like below.

PROC SQL;
CONNECT TO ORACLE(PATH="&DB." USER=&ID. ORAPW=&Password.);
CREATE TABLE dataset AS SELECT * FROM CONNECTION TO ORACLE
( SELECT
......
);
Disconnect from Oracle;
Quit;

%let COUNT1=&SQLOBS; %put &=COUNT1; ( sqlobs is coming as 0 , but my table 'dataset' has observations.
Tom
Super User Tom
Super User

So you aren't trying to count activity done inside of the remote database.  You are just waiting too long to capture the value of SQLOBS.  You have to get it before SQL runs another statement.

PROC SQL;
CONNECT TO ORACLE(PATH="&DB." USER=&ID. ORAPW=&Password.);
CREATE TABLE dataset AS SELECT * FROM CONNECTION TO ORACLE
( SELECT
......
);
%let COUNT1=&SQLOBS;
disconnect from Oracle;
quit;

%put &=COUNT1; 
SASAna
Quartz | Level 8
Thanks Tom. It worked well.
ChrisNZ
Tourmaline | Level 20
I thought the data was subsequently subset or joined in the SAS part of the code.Sigh......
ChrisNZ
Tourmaline | Level 20

I think you have to derive this count yourself.

For example with Oracle you can do something like:

proc sql noprint;
  connect using ORALIB;
  create table T as
  select * from connection to ORALIB ( 
    with Q as (  .. your oracle query... )
    select * 
    from Q
       , (select count(*) as COUNT from Q) 
  )  ...more SAS code, inner join, where etc....  ;
  select COUNT into :sqloraobs from T(obs=1);
%put &=sqloraobs ;

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 1212 views
  • 1 like
  • 4 in conversation