<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use &amp;quot;obs=&amp;quot; and &amp;quot;firstobs=&amp;quot; in cas actions? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854706#M337809</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp; for this explanation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works but it is slower than the data step load with an obs=1000 statement and a by descending sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By far the fastest solution I've found is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mkt.aki;
set myora.FACT_OPE_FORM(OBS=10000);
BY DESCENDING FECFORMO;
_fecformo=datepart(fecformo);
run;

proc summary data=mkt.aki print n;
class _fecformo;
format _fecformo year.;
var fk_obj;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What catches my eye with your fedsql code is the following:&lt;/P&gt;
&lt;P&gt;the limit option seems to have an effect like the obs option in a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 1000 observations written to the castable belong to the oldest records...&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jan 2023 21:45:40 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2023-01-19T21:45:40Z</dc:date>
    <item>
      <title>How to use "obs=" and "firstobs=" in cas actions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854526#M337717</link>
      <description>&lt;P&gt;I'm looking for a sibling of the obs= option for a cas action.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME myora ORACLE PATH=xxxxxx.vwfsag.de USER=SAS PASSWORD='xxxxxxx';

data MKT.aki(promote=no);
set myora.FACT_OPE_FORM(obs=10000);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I read only x rows for a cas action?&lt;/P&gt;
&lt;P&gt;It takes really long because it performs a serial load...&lt;/P&gt;
&lt;P&gt;Or I read only few rows or I convert this to parallel load.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: Active Session now mysession.
NOTE: Performing serial LoadTable action using SAS Data Connector to Oracle.
95   quit;
NOTE: The PROCEDURE CAS printed page 406.
NOTE: PROCEDURE CAS used (Total process time):
      real time           1:22.75
      cpu time            0.18 seconds
      
96   
97   %studio_hide_wrapper;
108  
109  &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cas;
   session mysession;
   simple.topk /  
      aggregator='N', topk=10, bottomk=0,                         
      inputs={"INDISMAN"},         
      casout={name='topk', caslib="public", replace=true},
      table={
         name="FACT_OPE_FORM", CASLIB="oracaslib",
         where="1=1", 
         computedVars={{name="year"}},
         computedVarsProgram="year=year(datepart(FECFORMO))",                     
         groupBy={'year'}};
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 10:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854526#M337717</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-01-19T10:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use "obs=" and "firstobs=" in cas actions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854704#M337808</link>
      <description>&lt;P&gt;To avoid haiving to load the entire DBMS table into CAS memory for processing, you need to first subset the rows in the database. And in CAS, only FedSQL can perform the implict or explicit pass-through to a database required to do that. So, reproduce the effect of OBS= in the DATA step, you can use FedSQL with the LIMIT clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fedsql sessref=mySession;
create table MKT.aki as
	select * 
		from myora.FACT_OPE_FORM
		limit 1000
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The DBMS SQL generated to retrieve the data will include the appropriate syntax to limit the number of rows retrieved. Because databases don't store their tables in a sequential format, the concept of FIRTSTOBS has no equivalent in DBMS SQL, so I know of no way to mimic that effect in the database.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for CAS actions themselves, the action may or may not provide options to limit the rows input or output (like the TO option for table.fetch), but because CAS actions only process CAS tables, the DBMS table data will have to have been pre-loaded into memory before running the action. So, the best answer is to use FedSQL to pre-load an abbreviated table, and&amp;nbsp;then process that with the CAS action.&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;Mark&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 21:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854704#M337808</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2023-01-19T21:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to use "obs=" and "firstobs=" in cas actions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854706#M337809</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp; for this explanation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works but it is slower than the data step load with an obs=1000 statement and a by descending sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By far the fastest solution I've found is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mkt.aki;
set myora.FACT_OPE_FORM(OBS=10000);
BY DESCENDING FECFORMO;
_fecformo=datepart(fecformo);
run;

proc summary data=mkt.aki print n;
class _fecformo;
format _fecformo year.;
var fk_obj;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What catches my eye with your fedsql code is the following:&lt;/P&gt;
&lt;P&gt;the limit option seems to have an effect like the obs option in a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 1000 observations written to the castable belong to the oldest records...&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 21:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-quot-obs-quot-and-quot-firstobs-quot-in-cas-actions/m-p/854706#M337809</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-01-19T21:45:40Z</dc:date>
    </item>
  </channel>
</rss>

