<?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: Auto generated output dataset name in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771661#M244928</link>
    <description>&lt;P&gt;Is that data set name 001 zeroes or captial O? The first isn't going to be a legal dataset name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you supply a valid data set name I think you want something closer to&lt;/P&gt;
&lt;PRE&gt;%macro getBlanks(indata=, prefix=);
   data &amp;amp;prefix.&amp;amp;indata.;
      set &amp;amp;indata.;
      if clinic =. and idnum =. then output;
   run;
%mend getBlanks;&lt;/PRE&gt;
&lt;P&gt;HOWEVER this does not account for Library. If your indata is in a library other than work you need to do more. Either provide the input library as a separate parameter (you can make it use work as default) and then if the OUTPUT goes to the same library reference or if you want it to a different library then additional parameter(s) may be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Oct 2021 19:07:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-01T19:07:22Z</dc:date>
    <item>
      <title>Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771643#M244919</link>
      <description>&lt;P&gt;I am trying to automatically generate the name of my output dataset. I want the name to include a prefix and the name of the input dataset.&lt;/P&gt;&lt;P&gt;For example, if the input dataset is: 001, I want the output dataset to be: X001.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See my code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro getBlanks(indata=, outdata=);&lt;BR /&gt;data &amp;amp;outdata.;&lt;BR /&gt;set &amp;amp;indata.;&lt;BR /&gt;if clinic =. and idnum =. then output &amp;amp;outdata.;&lt;BR /&gt;run;&lt;BR /&gt;%mend getBlanks;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%getBlanks (indata=001, outdata=blankRows);&amp;nbsp; &amp;nbsp; /*blankRows is a place holder*/&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 18:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771643#M244919</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-10-01T18:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771654#M244922</link>
      <description>Why not let base SAS autogenerate a work dataset that won't conglict with any pre-existing dataset? &lt;BR /&gt;The feature is _DATA_ &lt;BR /&gt;Using that as the output dataset name is convenient and reliable and unlikely to run into limits like the 32 character name limit (nor 256)</description>
      <pubDate>Fri, 01 Oct 2021 18:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771654#M244922</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-10-01T18:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771659#M244926</link>
      <description>&lt;P&gt;That's a really neat feature. I didn't know about it. Just tried it now and it works great.&lt;/P&gt;&lt;P&gt;In my case, I am not trying entirely generate random dataset names. I want to be able to look at the output dataset and relate it to the input dataset. So for example if the input dataset is 999, I want to output dataset to be something like X999.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 19:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771659#M244926</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-10-01T19:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771661#M244928</link>
      <description>&lt;P&gt;Is that data set name 001 zeroes or captial O? The first isn't going to be a legal dataset name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you supply a valid data set name I think you want something closer to&lt;/P&gt;
&lt;PRE&gt;%macro getBlanks(indata=, prefix=);
   data &amp;amp;prefix.&amp;amp;indata.;
      set &amp;amp;indata.;
      if clinic =. and idnum =. then output;
   run;
%mend getBlanks;&lt;/PRE&gt;
&lt;P&gt;HOWEVER this does not account for Library. If your indata is in a library other than work you need to do more. Either provide the input library as a separate parameter (you can make it use work as default) and then if the OUTPUT goes to the same library reference or if you want it to a different library then additional parameter(s) may be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 19:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771661#M244928</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-01T19:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771662#M244929</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

%macro getBlanks(indata=);
data X&amp;amp;indata.;
set &amp;amp;indata.;
if clinic =. and idnum =. then output &amp;amp;outdata.;
run;
%mend getBlanks;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are you planning to have actual names like 001? That doesn't follow the traditional SAS requirements, _001 is usual. You can use 001 but then you have to reference it as '001'n to differentiate the number from a data set so it becomes a pain though it's possible. If you're using traditional names, the method above should work perfectly fine for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're only outputting to one data set you can simplify this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getBlanks(indata=);
data X&amp;amp;indata.;
set &amp;amp;indata.;
where missing(clinic) and missing(idnum) ;
run;
%mend getBlanks;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have many data sets that have the same variables you can do this for all at once using shortcut references as well.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data blanks;
set X001-X999;
where missing(clinic) and missing(IDNUM);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364982"&gt;@nduksy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to automatically generate the name of my output dataset. I want the name to include a prefix and the name of the input dataset.&lt;/P&gt;
&lt;P&gt;For example, if the input dataset is: 001, I want the output dataset to be: X001.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See my code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro getBlanks(indata=, outdata=);&lt;BR /&gt;data &amp;amp;outdata.;&lt;BR /&gt;set &amp;amp;indata.;&lt;BR /&gt;if clinic =. and idnum =. then output &amp;amp;outdata.;&lt;BR /&gt;run;&lt;BR /&gt;%mend getBlanks;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%getBlanks (indata=001, outdata=blankRows);&amp;nbsp; &amp;nbsp; /*blankRows is a place holder*/&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 19:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771662#M244929</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-01T19:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771667#M244933</link>
      <description>Why not make the libref different. Then the table name remains</description>
      <pubDate>Fri, 01 Oct 2021 19:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771667#M244933</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-10-01T19:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771687#M244935</link>
      <description>&lt;P&gt;See below what I have so far. What I expect as an output dataset from the below is: &lt;STRONG&gt;bs017476a,&amp;nbsp;&lt;/STRONG&gt;but what I am getting is&amp;nbsp;&lt;STRONG&gt;b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro getBlanks(libr=, indata=, prefix=);&lt;BR /&gt;data &amp;amp;prefix.&amp;amp;indata.;&lt;BR /&gt;set &amp;amp;indata.;&lt;BR /&gt;if clinic =. or idnum =. then output;&lt;BR /&gt;run;&lt;BR /&gt;%mend getBlanks;&lt;/P&gt;&lt;P&gt;%getBlanks (libr=appl1 indata=s017476a, prefix=b);&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 20:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771687#M244935</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-10-01T20:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771690#M244936</link>
      <description>&lt;P&gt;Post your log. Your macro call is missing a comma, which may have generated an error. And you never use the libr parameter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without your IF statement, this example is analogous and works perfectly fine for me - please note the macro debugging options I've added to the top.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen;

%macro getBlanks(libr=, indata=, prefix=);
data &amp;amp;prefix.&amp;amp;indata.;
set &amp;amp;libr..&amp;amp;indata.;
run;
%mend getBlanks;

%getBlanks (libr=sashelp, indata=class, prefix=b);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364982"&gt;@nduksy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;See below what I have so far. What I expect as an output dataset from the below is: &lt;STRONG&gt;bs017476a,&amp;nbsp;&lt;/STRONG&gt;but what I am getting is&amp;nbsp;&lt;STRONG&gt;b&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro getBlanks(libr=, indata=, prefix=);&lt;BR /&gt;data &amp;amp;prefix.&amp;amp;indata.;&lt;BR /&gt;set &amp;amp;indata.;&lt;BR /&gt;if clinic =. or idnum =. then output;&lt;BR /&gt;run;&lt;BR /&gt;%mend getBlanks;&lt;/P&gt;
&lt;P&gt;%getBlanks (libr=appl1 indata=s017476a, prefix=b);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 20:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/771690#M244936</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-01T20:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Auto generated output dataset name in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/780981#M248892</link>
      <description>Often good to revisit old problems &lt;BR /&gt;Bring fresh perspective&lt;BR /&gt;&lt;BR /&gt;If you want to attach "source info" to a sas dataset, consider using the label of the output dataset.&lt;BR /&gt;There is lots of room (256+?) &lt;BR /&gt;Could store more than one table name &lt;BR /&gt;Plus extra info. like age of these sources &lt;BR /&gt;&lt;BR /&gt;Some table lists (like PROC CONTENTS) provide the label as well as name and can provide much more with the DETAILS  option</description>
      <pubDate>Thu, 18 Nov 2021 10:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-generated-output-dataset-name-in-macro/m-p/780981#M248892</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-11-18T10:17:18Z</dc:date>
    </item>
  </channel>
</rss>

