<?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: Create a file if the Have file as less than a number of records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398890#M96538</link>
    <description>&lt;P&gt;I think this is a good problem to wrap it all up in a macro using PROC SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(lib=,dsn=,size=);
  %local dsn size lib;

  proc sql noprint;
    select nobs into :nrecs from dictionary.tables 
    where libname="%upcase(&amp;amp;lib)" and memname="%upcase(&amp;amp;DSN)";

  %if &amp;amp;nrecs &amp;lt; &amp;amp;size %then create table error as select * from &amp;amp;lib..&amp;amp;dsn;;
  quit;
%mend;
%test(lib=sashelp,dsn=class,size=20);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Sep 2017 20:48:34 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-09-26T20:48:34Z</dc:date>
    <item>
      <title>Create a file if the Have file as less than a number of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398874#M96527</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I have a "have" file and it should have say 4 rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a error file if the "have" file has less than 4row.&lt;/P&gt;
&lt;P&gt;So in practice, when I see that error file, I know the issue.&lt;/P&gt;
&lt;P&gt;Can anyone help me with that?&lt;/P&gt;
&lt;P&gt;Thank you so much.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var;
datalines;
1
2
3
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Jan1 _1_jan Feb March_ ;
datalines;
1 0 0 0
2 1 1 1
;run;

data _null_;
call symput('nobs',put(x,best.));
set have nobs=x;
stop;
run;

%macro errout;
%if &amp;amp;nobs le 4 %then %do;
data have;
set  have;
notice= "not enough observations";
run;
%end;
%mend;
%errout;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Sep 2017 20:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398874#M96527</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-09-26T20:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a file if the Have file as less than a number of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398883#M96535</link>
      <description>&lt;P&gt;You can retrieve the number of observations in a dataset from sashelp.vtable or dictionary.tables (the latter with proc sql).&lt;/P&gt;
&lt;P&gt;Or you can run a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symput('nobs',put(x,best.));
set have nobs=x;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use that in a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro errout;
%if &amp;amp;nobs le 4 %then %do;
data _null_;
file "errorout";
put "not enough observations";
run;
%end;
%mend;
%errout&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Sep 2017 17:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398883#M96535</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-26T17:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a file if the Have file as less than a number of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398888#M96537</link>
      <description>&lt;P&gt;When I run your code, I receive this notice:&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access C:\Program Files\SASHome\SASFoundation\9.3\errorout.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using my computer and I am using Admin account.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure why it is like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 18:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398888#M96537</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-09-26T18:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a file if the Have file as less than a number of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398890#M96538</link>
      <description>&lt;P&gt;I think this is a good problem to wrap it all up in a macro using PROC SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(lib=,dsn=,size=);
  %local dsn size lib;

  proc sql noprint;
    select nobs into :nrecs from dictionary.tables 
    where libname="%upcase(&amp;amp;lib)" and memname="%upcase(&amp;amp;DSN)";

  %if &amp;amp;nrecs &amp;lt; &amp;amp;size %then create table error as select * from &amp;amp;lib..&amp;amp;dsn;;
  quit;
%mend;
%test(lib=sashelp,dsn=class,size=20);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Sep 2017 20:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398890#M96538</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-09-26T20:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a file if the Have file as less than a number of records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398892#M96540</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;When I run your code, I receive this notice:&lt;/P&gt;
&lt;P&gt;ERROR: Insufficient authorization to access C:\Program Files\SASHome\SASFoundation\9.3\errorout.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using my computer and I am using Admin account.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure why it is like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My filename was of course just a placeholder; use a name with an absolute path that points to a location where you have write permission.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 18:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-file-if-the-Have-file-as-less-than-a-number-of-records/m-p/398892#M96540</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-26T18:14:21Z</dc:date>
    </item>
  </channel>
</rss>

