<?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 Output is showing in log but want in sas dataset format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584896#M166698</link>
    <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I am running this code but the output result I am getting in SAS log. I want these output in a sas dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any solution will be appreciate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro list_files(dir,ext);&lt;BR /&gt;%local filrf rc did memcnt name i;&lt;BR /&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;%if &amp;amp;did eq 0 %then %do;&lt;BR /&gt;%put Directory &amp;amp;dir cannot be open or does not exist;&lt;BR /&gt;%return;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%do i = 1 %to %sysfunc(dnum(&amp;amp;did));&lt;/P&gt;&lt;P&gt;%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/P&gt;&lt;P&gt;%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;&lt;BR /&gt;%put &amp;amp;dir/&amp;amp;name;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %qscan(&amp;amp;name,2,.) = %then %do;&lt;BR /&gt;%list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;%let rc=%sysfunc(filename(filrf));&lt;/P&gt;&lt;P&gt;%mend list_files;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%list_files(/sasdata/im_pic_sas,sas)&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2019 12:00:54 GMT</pubDate>
    <dc:creator>benhaz</dc:creator>
    <dc:date>2019-08-29T12:00:54Z</dc:date>
    <item>
      <title>Output is showing in log but want in sas dataset format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584896#M166698</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I am running this code but the output result I am getting in SAS log. I want these output in a sas dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any solution will be appreciate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro list_files(dir,ext);&lt;BR /&gt;%local filrf rc did memcnt name i;&lt;BR /&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;%if &amp;amp;did eq 0 %then %do;&lt;BR /&gt;%put Directory &amp;amp;dir cannot be open or does not exist;&lt;BR /&gt;%return;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%do i = 1 %to %sysfunc(dnum(&amp;amp;did));&lt;/P&gt;&lt;P&gt;%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/P&gt;&lt;P&gt;%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;&lt;BR /&gt;%put &amp;amp;dir/&amp;amp;name;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %qscan(&amp;amp;name,2,.) = %then %do;&lt;BR /&gt;%list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;%let rc=%sysfunc(filename(filrf));&lt;/P&gt;&lt;P&gt;%mend list_files;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%list_files(/sasdata/im_pic_sas,sas)&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 12:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584896#M166698</guid>
      <dc:creator>benhaz</dc:creator>
      <dc:date>2019-08-29T12:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Output is showing in log but want in sas dataset format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584901#M166703</link>
      <description>&lt;P&gt;The %PUT statement writes to the LOG. If you don't want this, then you need to re-write the macro so that the results go to a SAS data set. In fact, if you search these forums, you will find many examples of the code that will write this information to the SAS data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, see Maxim 23.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 12:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584901#M166703</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-29T12:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Output is showing in log but want in sas dataset format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584904#M166705</link>
      <description>&lt;P&gt;Instead of %PUTting things to the log, create statements (because creating code is what the macro processor is meant to do):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext);
%local filrf rc did memcnt name i;
%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
%let did=%sysfunc(dopen(&amp;amp;filrf));

%if &amp;amp;did eq 0 %then %do;
%put Directory &amp;amp;dir cannot be open or does not exist;
%return;
%end;

%do i = 1 %to %sysfunc(dnum(&amp;amp;did));

%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
fname = "&amp;amp;dir/&amp;amp;name";
output;
%end;
%else %if %qscan(&amp;amp;name,2,.) = %then %do;
%list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)
%end;

%end;
%let rc=%sysfunc(dclose(&amp;amp;did));
%let rc=%sysfunc(filename(filrf));

%mend list_files;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then use the macro in the proper place:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data myfiles;
length fname $200;
%list_files(your_path,sas)
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 12:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584904#M166705</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-29T12:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Output is showing in log but want in sas dataset format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584908#M166707</link>
      <description>&lt;P&gt;Thank You Sir! This is working.&lt;/P&gt;&lt;P&gt;Appreciate your help!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 12:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584908#M166707</guid>
      <dc:creator>benhaz</dc:creator>
      <dc:date>2019-08-29T12:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Output is showing in log but want in sas dataset format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584919#M166711</link>
      <description>&lt;P&gt;Another option is to add functionality to the macro so that you have the option of either writing to the log or creating an output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within the macro, it would need to generate the full code for a DATA step.&amp;nbsp; With a recursive macro like this, it takes a bit more thinking.&amp;nbsp; Because on the first iteration only, you want it to start writing the DATA step.&amp;nbsp; Then on every iteration it outputs a record.&amp;nbsp; And at the end of the first iteration it ends the DATA step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext,out=);
  %local filrf rc did memcnt name i;
  %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
  %let did=%sysfunc(dopen(&amp;amp;filrf));

  
  %*If out= was specified, and not one of the recursive calls, start writing a data step ;
  %if %superq(out) ne %str() and %sysmexecname(%sysmexecdepth - 1) ne LIST_FILES 
  %then %do;
    data &amp;amp;out ;
      length path $200 ; *Pick a longer length if you have longer paths ;
  %end;


  %if &amp;amp;did eq 0 %then %do;
    %put Directory &amp;amp;dir cannot be open or does not exist;
    %return;
  %end;

  %do i = 1 %to %sysfunc(dnum(&amp;amp;did));
    %let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));
    %if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
      %put &amp;amp;dir/&amp;amp;name;

      %*Write the path to output dataset ;
      %if %superq(out) ne %str() %then %do ;
        path="&amp;amp;dir/&amp;amp;name" ;
        output ;
      %end ;
    %end;
    %else %if %qscan(&amp;amp;name,2,.) = %then %do;
      %list_files(&amp;amp;dir/&amp;amp;name,&amp;amp;ext)
    %end;
  %end;

  %*If out= was specified, and not one of the recursive calls, end the data step ;
  %if %superq(out) ne %str() and %sysmexecname(%sysmexecdepth - 1) ne LIST_FILES 
  %then %do;
    run ;
  %end;


  %let rc=%sysfunc(dclose(&amp;amp;did));
  %let rc=%sysfunc(filename(filrf));

%mend list_files;

options mprint ;
%list_files(/sasdata/im_pic_sas, sas, out=work.want)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Aug 2019 12:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-is-showing-in-log-but-want-in-sas-dataset-format/m-p/584919#M166711</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-08-29T12:46:47Z</dc:date>
    </item>
  </channel>
</rss>

