<?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 How to retain summary information across runs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-summary-information-across-runs/m-p/540186#M148974</link>
    <description>&lt;P&gt;Here's a method I use to retain summary information across many SAS runs. Summary information could include information like number of records, run time, or file sizes. In this example I want to track how many records are in 3 tables, each time the SAS job executes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;General approach:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Make an empty table with the desired structure to hold desired information.&lt;OL&gt;&lt;LI&gt;Store on disk, not in saswork, since we want to read/write to this table often across batch jobs and SAS sessions&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Loop though tables/fields/whatever you want to process and grab the desired information&lt;/LI&gt;&lt;LI&gt;Place summary information into temporary table, then add temporary table to permanent table&lt;OL&gt;&lt;LI&gt;Include timestamp of rundate&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Monitor/reference permanent table as desired!&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname local 'xxxxx';

%macro log_summary_information(tables_to_process);
	
	*1. make empty summary table with correct metadata if it does not already exist;
	%if not %sysfunc(exist(local.stacked_counts)) %then %do;
		data local.stacked_counts;
			length table_name $50 record_count run_time 8.;
			format run_time datetime.;
			stop;
		run;
	%end;

	%let to_loop_count = %eval(%sysfunc(countc(&amp;amp;tables_to_process," "))+1);
	%put will process &amp;amp;to_loop_count tables &amp;amp;tables_to_process;

	*2. loop through tables and get desired information;
	%do i = 1 %to &amp;amp;to_loop_count;
		%let table = %scan(&amp;amp;tables_to_process,&amp;amp;i," ");
		%put Processing &amp;amp;table;

		*2. grab record counts/desired information;
		%let dsid = %sysfunc(open(&amp;amp;table));
		%let count =%sysfunc(attrn(&amp;amp;dsid,nobs));
		%let rc = %sysfunc(close(&amp;amp;dsid));
		
		*3. create summary record and append to growing summary table;
		data temp_record;
			table_name ="&amp;amp;table";
			record_count=&amp;amp;count;
			run_time=datetime();
		run;
		proc append base=local.stacked_counts data=temp_record force;
		run;
	%end;
	
%mend;
%let tables_to_process=sashelp.cars sashelp.class sashelp.baseball;
%log_summary_information(&amp;amp;tables_to_process)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I ran this twice, and the record counts are the same (duh - referencing static SASHELP tables), but this could change depending on your context.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 390px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27643iC4825206A69E4501/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2019 19:46:34 GMT</pubDate>
    <dc:creator>noling</dc:creator>
    <dc:date>2019-03-04T19:46:34Z</dc:date>
    <item>
      <title>How to retain summary information across runs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-summary-information-across-runs/m-p/540186#M148974</link>
      <description>&lt;P&gt;Here's a method I use to retain summary information across many SAS runs. Summary information could include information like number of records, run time, or file sizes. In this example I want to track how many records are in 3 tables, each time the SAS job executes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;General approach:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Make an empty table with the desired structure to hold desired information.&lt;OL&gt;&lt;LI&gt;Store on disk, not in saswork, since we want to read/write to this table often across batch jobs and SAS sessions&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Loop though tables/fields/whatever you want to process and grab the desired information&lt;/LI&gt;&lt;LI&gt;Place summary information into temporary table, then add temporary table to permanent table&lt;OL&gt;&lt;LI&gt;Include timestamp of rundate&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Monitor/reference permanent table as desired!&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname local 'xxxxx';

%macro log_summary_information(tables_to_process);
	
	*1. make empty summary table with correct metadata if it does not already exist;
	%if not %sysfunc(exist(local.stacked_counts)) %then %do;
		data local.stacked_counts;
			length table_name $50 record_count run_time 8.;
			format run_time datetime.;
			stop;
		run;
	%end;

	%let to_loop_count = %eval(%sysfunc(countc(&amp;amp;tables_to_process," "))+1);
	%put will process &amp;amp;to_loop_count tables &amp;amp;tables_to_process;

	*2. loop through tables and get desired information;
	%do i = 1 %to &amp;amp;to_loop_count;
		%let table = %scan(&amp;amp;tables_to_process,&amp;amp;i," ");
		%put Processing &amp;amp;table;

		*2. grab record counts/desired information;
		%let dsid = %sysfunc(open(&amp;amp;table));
		%let count =%sysfunc(attrn(&amp;amp;dsid,nobs));
		%let rc = %sysfunc(close(&amp;amp;dsid));
		
		*3. create summary record and append to growing summary table;
		data temp_record;
			table_name ="&amp;amp;table";
			record_count=&amp;amp;count;
			run_time=datetime();
		run;
		proc append base=local.stacked_counts data=temp_record force;
		run;
	%end;
	
%mend;
%let tables_to_process=sashelp.cars sashelp.class sashelp.baseball;
%log_summary_information(&amp;amp;tables_to_process)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I ran this twice, and the record counts are the same (duh - referencing static SASHELP tables), but this could change depending on your context.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 390px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27643iC4825206A69E4501/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 19:46:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-summary-information-across-runs/m-p/540186#M148974</guid>
      <dc:creator>noling</dc:creator>
      <dc:date>2019-03-04T19:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain summary information across runs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-summary-information-across-runs/m-p/540193#M148977</link>
      <description>Cool...though I think I'd want to add a check of the date created/modified so I didn't add duplicate records (replacing 'run_time' with the max of created/modified).&lt;BR /&gt;&lt;BR /&gt;            dateCreate = finfo(_fid, "Create Time");&lt;BR /&gt;            dateModify = finfo(_fid, "Last Modified");</description>
      <pubDate>Mon, 04 Mar 2019 20:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-summary-information-across-runs/m-p/540193#M148977</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-03-04T20:02:39Z</dc:date>
    </item>
  </channel>
</rss>

