<?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 assign a Count of dataset to variable and use it in IF ELSE statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438356#M69090</link>
    <description>&lt;P&gt;Why?&amp;nbsp; Every dataset within the SAS system already has metadata associated with the dataset stored.&amp;nbsp; You can access this metadata directly by using the sashelp.vtable (and if you want columns, sashelp.vcolumn) or via the SQL syntax of dictionary.tables.&amp;nbsp; Therefore you a) do not need to code this yourself, and b) do not need to store the numeric in a text macro variable.&amp;nbsp; So for instance:&lt;/P&gt;
&lt;PRE&gt;set cnt=(select nobs from sashelp.vtable where libname="WORK" and memname="ABC");&lt;/PRE&gt;
&lt;P&gt;Assuming your dataset is work.abc.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Feb 2018 09:14:23 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-02-19T09:14:23Z</dc:date>
    <item>
      <title>How to assign a Count of dataset to variable and use it in IF ELSE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438347#M69086</link>
      <description>&lt;P&gt;I want to store count of dataset in variable like below&lt;/P&gt;&lt;P&gt;%let Cnt ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create table work.delaycheck as&lt;BR /&gt;select * from connection to oracle&lt;BR /&gt;(&lt;/P&gt;&lt;P&gt;SELECT PTNR_ID,CLNT_ID,REPORTING_DATE_KEY,NET_SALES&lt;BR /&gt;FROM FACT_TABLE&lt;/P&gt;&lt;P&gt;MINUS&lt;/P&gt;&lt;P&gt;SELECT PTNR_ID,CLNT_ID,REPORTING_DATE_KEY,NET_SALES&lt;BR /&gt;FROM HIST_FCT&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store count of this table in the variable Cnt like below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set Cnt = (Select count(*) from work.delaycheck )&lt;/P&gt;&lt;P&gt;And Then&lt;/P&gt;&lt;P&gt;If(Cnt=0)&lt;/P&gt;&lt;P&gt;THEN&lt;/P&gt;&lt;P&gt;DO NOTHING&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;execute(&lt;/P&gt;&lt;P&gt;Insert into Oracle_table&lt;/P&gt;&lt;P&gt;select * from work.delaycheck&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;) by oracle;&lt;/P&gt;&lt;P&gt;disconnect from oracle;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I acheive these steps? Thanks In advance!!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 07:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438347#M69086</guid>
      <dc:creator>Pradeepbanu</dc:creator>
      <dc:date>2018-02-19T07:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign a Count of dataset to variable and use it in IF ELSE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438356#M69090</link>
      <description>&lt;P&gt;Why?&amp;nbsp; Every dataset within the SAS system already has metadata associated with the dataset stored.&amp;nbsp; You can access this metadata directly by using the sashelp.vtable (and if you want columns, sashelp.vcolumn) or via the SQL syntax of dictionary.tables.&amp;nbsp; Therefore you a) do not need to code this yourself, and b) do not need to store the numeric in a text macro variable.&amp;nbsp; So for instance:&lt;/P&gt;
&lt;PRE&gt;set cnt=(select nobs from sashelp.vtable where libname="WORK" and memname="ABC");&lt;/PRE&gt;
&lt;P&gt;Assuming your dataset is work.abc.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 09:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438356#M69090</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-19T09:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign a Count of dataset to variable and use it in IF ELSE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438917#M69114</link>
      <description>&lt;P&gt;Why do you want to make the insert conditional? When the table is empty, inserting in into another table does exactly nothing, and takes very little time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if you need to know this for other reasons, PROC SQL assigns the macro variable SQLOBS, which contains the number of rows in the output from the last SQL statement. So you could use that like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro insert;
proc SQL;
  /* code to create work table here */
%if &amp;amp;sqlobs&amp;gt;0 %then %do;
  /* code to do something with table here */
  %end;
quit;
%mend;

%insert;  
  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Of course, you cannot use a SQL EXECUTE call to insert rows from a SAS table. You would either have to load the data to a (temporary) Oracle table, and the perform the insert. Alternatively, you can assign the Oracle schema as a SAS libname and use e.g. PROC APPEND to insert your data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
  connect to Oracle(&amp;lt;connnect options&amp;gt;);
  create table work.delaycheck as select * from connection to Oracle
    (&amp;lt;Oracle select code&amp;gt;);
quit;

libname outlib Oracle &amp;lt;connect options&amp;gt;;
proc append data=delaycheck base=outlib.Oracle_table;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Feb 2018 12:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-assign-a-Count-of-dataset-to-variable-and-use-it-in-IF/m-p/438917#M69114</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-02-21T12:49:11Z</dc:date>
    </item>
  </channel>
</rss>

