<?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: Can we get count of rows in a macro variable for a blank dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471667#M120843</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179995"&gt;@Sharathr&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;For the discussion &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt; references I'd write the macro a bit differently as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_table_size(inset,macvar);
  %global &amp;amp;macvar;
  data _null_;
    call symput("&amp;amp;macvar",put(nobs,f15. -l));
    stop;
    set &amp;amp;inset nobs=nobs;
  run;
%mend;



%get_table_size(sashelp.class,n_obs)
%put &amp;amp;=n_obs;

data test;
  length var 8;
  stop;
run;
%get_table_size(test,n_obs)
%put &amp;amp;=n_obs;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Jun 2018 12:47:12 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2018-06-20T12:47:12Z</dc:date>
    <item>
      <title>Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471645#M120836</link>
      <description>How to count the rows of dataset and assign it macro variable?if the dataset is blank then it has to have macro variable value as 0 .kindly help.</description>
      <pubDate>Wed, 20 Jun 2018 11:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471645#M120836</guid>
      <dc:creator>Sharathr</dc:creator>
      <dc:date>2018-06-20T11:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471649#M120839</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following contains a solution to the same question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/td-p/6234" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-get-count-of-total-records-in-a-table/td-p/6234&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: You can assign the macro variable a value of 0 before trying to find the actual value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 11:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471649#M120839</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2018-06-20T11:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471652#M120840</link>
      <description>&lt;P&gt;untested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let count = 0;
proc sql noprint;
  select nobs into :count trimmed
    from sashelp.vtable
      where libname = "LIB" and memname = "DATASET"
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that library and dataset-name have to be all upcase.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 11:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471652#M120840</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-06-20T11:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471654#M120842</link>
      <description>&lt;P&gt;Why do you need it in a macro variable?&amp;nbsp; The reason I ask is is because there are better methods to run code if observations exist, and in most scenarios code will run even if there are no observations.&amp;nbsp; So there is rarely or never a need to create a macro variable for this, especially since the data is already present in sashelp.vtable, e.g.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="&amp;lt;yourlib&amp;gt;" and memname="&amp;lt;yourds&amp;gt;"));
  call symputx('num_obs',nobs);
run;

%put &amp;amp;num_obs.;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jun 2018 12:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471654#M120842</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-20T12:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471667#M120843</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179995"&gt;@Sharathr&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;For the discussion &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22588"&gt;@Amir&lt;/a&gt; references I'd write the macro a bit differently as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get_table_size(inset,macvar);
  %global &amp;amp;macvar;
  data _null_;
    call symput("&amp;amp;macvar",put(nobs,f15. -l));
    stop;
    set &amp;amp;inset nobs=nobs;
  run;
%mend;



%get_table_size(sashelp.class,n_obs)
%put &amp;amp;=n_obs;

data test;
  length var 8;
  stop;
run;
%get_table_size(test,n_obs)
%put &amp;amp;=n_obs;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jun 2018 12:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/471667#M120843</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-20T12:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698584#M213665</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;. I just used this little code snippet (thank you very much, its greatly appreciated), but I don't understand what the f15. -l clause is within the put statement. I understand its probably just a format, but I can't find any documentation on it anywhere. Any chance you could shed some light on what this is?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 07:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698584#M213665</guid>
      <dc:creator>dh735</dc:creator>
      <dc:date>2020-11-13T07:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698585#M213666</link>
      <description>&lt;P&gt;The -l modifier causes the PUT function to left-align the result after applying the format. Numeric formats right-align per default.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 08:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698585#M213666</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-13T08:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698587#M213668</link>
      <description>&lt;P&gt;You can simplify the data step by using SYMPUTX:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    call symputx("&amp;amp;macvar",nobs);
    stop;
    set &amp;amp;inset nobs=nobs;
  run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SYMPUTX does the conversion from numeric to character without issuing a NOTE, and removes leading and trailing blanks from the second argument.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 08:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698587#M213668</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-13T08:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get count of rows in a macro variable for a blank dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698615#M213677</link>
      <description>&lt;P&gt;Seeing as you necro'd an old thread, I thought I would point out:&lt;/P&gt;
&lt;P&gt;SAS Creates macro variables at the end of each step:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=vdmmlcdc&amp;amp;cdcVersion=8.1&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p0t267pk8lwx3en1gn9fywjgni8y.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=vdmmlcdc&amp;amp;cdcVersion=8.1&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p0t267pk8lwx3en1gn9fywjgni8y.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;And SQL is sqlobs.&lt;/P&gt;
&lt;P&gt;So if you need it inline with your code then you can use that after the step.&amp;nbsp; If you need observations elsewhere for some reason, then there is the SASHELP.VTABLE view which holds observations for all data tables (except external linked databases), so you can always get the obs from there.&amp;nbsp; Depends on what you need it for.&amp;nbsp; Rarely useful to recreate to have your own macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 10:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-get-count-of-rows-in-a-macro-variable-for-a-blank-dataset/m-p/698615#M213677</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2020-11-13T10:18:42Z</dc:date>
    </item>
  </channel>
</rss>

