<?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 including filename in proc means output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226690#M40829</link>
    <description>&lt;P&gt;Hello! Im wondering if there is a way to include the filename in the output for proc mean. I have a loop that does proc mean for a series of files, but in the output I only get the varname to identify each output I would also like to add the file name&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;&lt;P&gt;%macro do_nftest (allanftest);&lt;/P&gt;&lt;P&gt;%do p=1 %to %sysfunc(countw(&amp;amp;allanftest));&lt;BR /&gt;proc means data= %scan(&amp;amp;allanftest,&amp;amp;p);&lt;BR /&gt;var fr11;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%do_nftest(&amp;amp;allanftest.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankful for any help!&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Sep 2015 08:10:42 GMT</pubDate>
    <dc:creator>Caroline1620_</dc:creator>
    <dc:date>2015-09-22T08:10:42Z</dc:date>
    <item>
      <title>including filename in proc means output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226690#M40829</link>
      <description>&lt;P&gt;Hello! Im wondering if there is a way to include the filename in the output for proc mean. I have a loop that does proc mean for a series of files, but in the output I only get the varname to identify each output I would also like to add the file name&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;&lt;P&gt;%macro do_nftest (allanftest);&lt;/P&gt;&lt;P&gt;%do p=1 %to %sysfunc(countw(&amp;amp;allanftest));&lt;BR /&gt;proc means data= %scan(&amp;amp;allanftest,&amp;amp;p);&lt;BR /&gt;var fr11;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%do_nftest(&amp;amp;allanftest.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankful for any help!&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2015 08:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226690#M40829</guid>
      <dc:creator>Caroline1620_</dc:creator>
      <dc:date>2015-09-22T08:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: including filename in proc means output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226695#M40832</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Can you provide example of your data, and example of your output as its not clear just from the code. &amp;nbsp;If you want the dataset name in the output then a simple change of mindset from repeating code to setting your data together and by group processing it. &amp;nbsp;E.g.&lt;/P&gt;&lt;P&gt;I have three datasets A, B, C:&lt;/P&gt;&lt;P&gt;data for_test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set a (in=a) b (in=b) c (in=c);&lt;/P&gt;&lt;P&gt;&amp;nbsp; length dataset_name $8;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if a then dataset_name="A";&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if b then dataset_name="B";&lt;/P&gt;&lt;P&gt;&amp;nbsp; else dataset_name="C";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc means data=for_test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by dataset_name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var fr11;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=results n=n ...;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see form the above, I combine my data, then run one proc means with a by grouping on it. &amp;nbsp;This is both easier to code, and is better performance, no need for macro code at all.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2015 08:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226695#M40832</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-09-22T08:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: including filename in proc means output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226714#M40835</link>
      <description>Or something like:&lt;BR /&gt;&lt;BR /&gt;data _V/view=_V;&lt;BR /&gt;set &amp;amp;allanftest. indsname=_IN;&lt;BR /&gt;SOURCE=_IN;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data= _V;&lt;BR /&gt;by SOURCE notsorted;&lt;BR /&gt;var FR11;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 22 Sep 2015 11:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226714#M40835</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-09-22T11:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: including filename in proc means output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226719#M40836</link>
      <description>&lt;P&gt;Nice, I always forget the indsname option.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2015 12:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226719#M40836</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-09-22T12:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: including filename in proc means output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226727#M40838</link>
      <description>&lt;P&gt;I don't know if this meets your needs, but you could easily put the filename in the title.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;title "Using Data Set %scan(&amp;amp;allanftest,&amp;amp;p)";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2015 13:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/226727#M40838</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-09-22T13:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: including filename in proc means output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/231133#M42015</link>
      <description>&lt;P&gt;Hi Caroline,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do this by making a table list of the files in that directory, then you substr() the&lt;/P&gt;
&lt;P&gt;var to get only the file name, create a variable as an ID that set first file as 1 and so on.&lt;/P&gt;
&lt;P&gt;The syntax would be similar to this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename file "ls /path/*.txt";

data test;
   length entire_row $ 160;
   infile file;
   input entire_row;
run;

data test2;
   set test;
   id = _N_;
   new_row = substr(entire_row,1,1);
run;
 
/*Here create a macro with %do loop to recognize the id*/

proc sql noprint;
   select new_row into: nfile&amp;amp;i. from test2
   where id = &amp;amp;i.;
quit;
&lt;/PRE&gt;
&lt;P&gt;In proc sql create a macro step to create&amp;nbsp;multiple macros containing file names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After this use in your proc means %do loop, i would say to put in the same&lt;/P&gt;
&lt;P&gt;%do loop to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Att&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 13:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/including-filename-in-proc-means-output/m-p/231133#M42015</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-10-22T13:01:06Z</dc:date>
    </item>
  </channel>
</rss>

