<?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: add the number of obs in each dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105831#M22052</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks! the dataset name is correct. after adding the code to preset the default value, there is no error message anymore. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Dec 2012 16:43:45 GMT</pubDate>
    <dc:creator>jojo</dc:creator>
    <dc:date>2012-12-21T16:43:45Z</dc:date>
    <item>
      <title>add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105824#M22045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to count obs in each dataset created in a macro and add them up to get the sum . My code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro p (num1, num2);&lt;/P&gt;&lt;P&gt;%do i=2 %to &amp;amp;num1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do j=2 %to &amp;amp;num2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %s1(&amp;amp;a,&amp;amp;b,&amp;amp;c,&amp;amp;d); *** create data2 here;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *** I need to count the number of obs in each data2 created in each loop and get the total number of obs in all data2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%end;%end;%end;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help will be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 17:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105824#M22045</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2012-12-20T17:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105825#M22046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you need to count, as the individual counts are used, or just the total number of observations? Are these separate datasets or are you overwriting Data2 each time through the loop?&lt;/P&gt;&lt;P&gt;If you have not been overwriting and each output set has it's own name and been clever and placed them in there own library the following might help:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sql; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select sum(nobs) AS TotalObs &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from dictionary.tables &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where libname='SASHELP'&amp;nbsp; /* your library here*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you have other sets in that library you don't want to include then an additional part of the where clause woud be needed similar to&lt;/P&gt;&lt;P&gt;where libname='YOURLIBNAME' and memname in (&lt;/P&gt;&lt;P&gt;/* a repeat of your macro looping that results in each dataset name in upper case*/&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 18:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105825#M22046</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-12-20T18:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105826#M22047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the individual counts are not used, only the total sum is used, but there will be some empty data2, I need to exclude them. I am overwriting the data2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 18:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105826#M22047</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2012-12-20T18:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105827#M22048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%macro p (num1, num2);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;%GLOBAL TOTAL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;%LET TOTAL=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%do i=2 %to &amp;amp;num1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do j=2 %to &amp;amp;num2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %s1(&amp;amp;a,&amp;amp;b,&amp;amp;c,&amp;amp;d); *** create data2 here;&lt;/P&gt;&lt;P&gt;&amp;nbsp; *** I need to count the number of obs in each data2 created in each loop and get the total number of obs in all data2; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;select CATS(nobs) into :nobs from dictionary.tables where LIBNAME='WORK' AND UPCASE(MEMNAME)='DATA2';QUIT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&amp;nbsp; %LET TOTAL=%EVAL(&amp;amp;NOBS.+&amp;amp;TOTAL.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%end;%end;%end;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT TOTAL= &amp;amp;TOTAL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically you add up total records to a macro variable after each time a new table being built or rewrite.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 19:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105827#M22048</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-12-20T19:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105828#M22049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;got a message:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference NOBS not resolved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference NOBS not resolved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is required. The condition was: &amp;amp;NOBS.+0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: The macro P will stop executing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 19:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105828#M22049</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2012-12-20T19:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105829#M22050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The solution looks right.&amp;nbsp; Most likely, you omitted the colon after INTO.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 20:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105829#M22050</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-12-20T20:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105830#M22051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unless you have syntax error that is probably caused by there NOT being a dataset named DATA2.&amp;nbsp; You should probably fix this issue first. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that when use SQL to generate a macro variable it is usually best to preset the default value that you want in case the query does not find any matching records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let nobs=0;&lt;/P&gt;&lt;P&gt;select nobs into :nobs&lt;/P&gt;&lt;P&gt;&amp;nbsp; from dictionary.tables&lt;/P&gt;&lt;P&gt;&amp;nbsp; where libname='WORK' &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and memname='DATA2'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%let total = %eval(&amp;amp;nobs + &amp;amp;total);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 20:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105830#M22051</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-20T20:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105831#M22052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks! the dataset name is correct. after adding the code to preset the default value, there is no error message anymore. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 16:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105831#M22052</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2012-12-21T16:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105832#M22053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A small trick should let this work even if you forget to set the default value (as long as the %GLOBAL statement is still there):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let total = %eval(&amp;amp;total +&amp;amp;nobs);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Leave out the space after "+" and it will generate a legitimate numeric even when &amp;amp;TOTAL is null.&amp;nbsp; (Also note how CATS removed any leading and trailing blanks from &amp;amp;NOBS.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 17:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105832#M22053</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-12-21T17:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: add the number of obs in each dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105833#M22054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Liked and learned. The problem for me is that there are too many tricks and I keep forgetting them. The other day it even took me long to understand a piece of short code I wrote myself. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 17:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-the-number-of-obs-in-each-dataset/m-p/105833#M22054</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-12-21T17:35:51Z</dc:date>
    </item>
  </channel>
</rss>

