<?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: Creating macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571153#M161105</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204061"&gt;@KalaBhairava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your replay Sir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want set&amp;nbsp; all datasets , it should be separately and macro variable should create in all datasets.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Huh?&amp;nbsp; This makes no sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I promise I'm not trolling.&amp;nbsp; But if English isn't your native language, do you have a colleague who can help you clearly state what you are trying to do?&amp;nbsp; I think that will help a lot in us helping you better.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jul 2019 06:31:44 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2019-07-04T06:31:44Z</dc:date>
    <item>
      <title>Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571128#M161091</link>
      <description>&lt;P&gt;Hi Every one,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have 10 data&amp;nbsp;sets (AA,BB,CC,DD,EE,FF,GG,HH) in one library and i want create macro to convert data set name into variable name (New ).&lt;/P&gt;&lt;P&gt;for ex: for AA data set i want variable New =AA&lt;/P&gt;&lt;P&gt;for BB data set i want variable New =BB;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please give me a solution.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571128#M161091</guid>
      <dc:creator>KalaBhairava</dc:creator>
      <dc:date>2019-07-04T05:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571131#M161093</link>
      <description>&lt;P&gt;Sounds strange, that you want a variable in a dataset with the same name as the dataset. What do you want to do with that variable? What type and length should it have?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571131#M161093</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-07-04T05:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571132#M161094</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably don't need to do what you are requesting.&lt;/P&gt;
&lt;P&gt;Read about the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;indsname&lt;/FONT&gt; option.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571132#M161094</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-07-04T05:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571133#M161095</link>
      <description>&lt;P&gt;You don't need a macro. Simply use the &lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p00hxg3x8lwivcn1f0e9axziw57y.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Indsname Option in the Set Statement&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571133#M161095</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-07-04T05:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571134#M161096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204061"&gt;@KalaBhairava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Every one,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have 10 data&amp;nbsp;sets (AA,BB,CC,DD,EE,FF,GG,HH) in one library and i want create macro to convert data set name into variable name (New ).&lt;/P&gt;
&lt;P&gt;for ex: for AA data set i want variable New =AA&lt;/P&gt;
&lt;P&gt;for BB data set i want variable New =BB;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please give me a solution.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's only 8 datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Define "variable".&amp;nbsp; We need more context.&amp;nbsp; What do you really need to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aa bb cc dd ee ff gg hh ii jj;
   x=1;
run;

* delete the _PRODSAVAIL dataset ;
proc datasets lib=work kill nowarn nolist;
quit;

proc sql noprint;
   select catx('.',libname,memname) into :datasets separated by ' '
   from dictionary.tables
   where libname='WORK';
quit;

%put &amp;amp;=datasets;

%macro code;
   %let new=&amp;amp;word;
   %put &amp;amp;=new;
%mend;
%loop(&amp;amp;datasets)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add&amp;nbsp;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/loop.sas" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/blob/master/Macro/loop.sas&lt;/A&gt;&amp;nbsp;to your macro autocall library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select catx('.',libname,memname) into :datasets separated by ' '&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;to&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select memname into :datasets separated by ' '&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you just want the member name only.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571134#M161096</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-04T05:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571149#M161101</link>
      <description>&lt;P&gt;Hi Sir,&lt;/P&gt;&lt;P&gt;for CDISC studies(Clinical trails) we have to create variable Domin and it should contain data set name.&amp;nbsp; and length also minum $2 and max 5.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 06:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571149#M161101</guid>
      <dc:creator>KalaBhairava</dc:creator>
      <dc:date>2019-07-04T06:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571150#M161102</link>
      <description>&lt;P&gt;As already mentioned, use the indsname= option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set
  aa
  bb
  cc
  dd
  ee
  ff
  gg
  hh
  indsname=inds
;
length domin $5;
domin = inds;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Be aware that restricting the length of SAS dataset names may be up to 32, so restricting it to 5 is a disaster waiting to happen. Someday someone will apply your macro to a bunch of datasets with longer names.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 06:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571150#M161102</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-04T06:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571151#M161103</link>
      <description>&lt;P&gt;Thanks for your replay Sir.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want set&amp;nbsp; all datasets , it should be separately and macro variable should create in all datasets.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 06:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571151#M161103</guid>
      <dc:creator>KalaBhairava</dc:creator>
      <dc:date>2019-07-04T06:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571152#M161104</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204061"&gt;@KalaBhairava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your replay Sir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want set&amp;nbsp; all datasets , it should be separately and macro variable should create in all datasets.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Macro variables exist outside datasets, so this is not possible.&lt;/P&gt;
&lt;P&gt;If you have trouble describing what you want, supply example data and show the expected outcome.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 06:29:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571152#M161104</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-04T06:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571153#M161105</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204061"&gt;@KalaBhairava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your replay Sir.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want set&amp;nbsp; all datasets , it should be separately and macro variable should create in all datasets.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Huh?&amp;nbsp; This makes no sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I promise I'm not trolling.&amp;nbsp; But if English isn't your native language, do you have a colleague who can help you clearly state what you are trying to do?&amp;nbsp; I think that will help a lot in us helping you better.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 06:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571153#M161105</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-04T06:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571250#M161141</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204061"&gt;@KalaBhairava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Every one,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have 10 data&amp;nbsp;sets (AA,BB,CC,DD,EE,FF,GG,HH) in one library and i want create macro to convert data set name into variable name (New ).&lt;/P&gt;
&lt;P&gt;for ex: for AA data set i want variable New =AA&lt;/P&gt;
&lt;P&gt;for BB data set i want variable New =BB;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;please give me a solution.&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Would you walk up to someone and say "please give me a solution"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro addName(indsn=, outdsn=, varName=);

data &amp;amp;outdsn.;
set &amp;amp;indsn;
&amp;amp;varName = "&amp;amp;indsn.";
run;

%mend;

%addName(indsn=AA, outdsn=AA_New, varName=);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now to call it for all data sets in a library, use CALL EXECUTE and SASHELP.VTABLE.&lt;/P&gt;
&lt;PRE&gt;data demo;
set sashelp.vtable;
where libname = 'CDISCXX'; *can add filtering conditions here;

&lt;FONT size="4" color="#FF6600"&gt;str = catt('%addName(indsn=', 
                                    memname, 
                                    ', outdsn=',
                                     catx("_", memname, "new"), 
                                     ", varName=New",
                                     ");"
                 );&lt;/FONT&gt;

call execute(str);
 
run;&lt;/PRE&gt;
&lt;P&gt;Make sure str is being calculated correctly after you've test it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, first make sure your base code is working and then you can convert any program into a macro using this approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS. "please give me a solution" isn't something most people would ever say, it's more likely you intended to say "please help me with this problem", because this isn't a coding service where you're entitled to a solution or someone will write the code for you, this is a community of volunteers who you're asking for help. I'm going to assume that this is a just a translation issue.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/204061"&gt;@KalaBhairava&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Every one,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i have 10 data&amp;nbsp;sets (AA,BB,CC,DD,EE,FF,GG,HH) in one library and i want create macro to convert data set name into variable name (New ).&lt;/P&gt;
&lt;P&gt;for ex: for AA data set i want variable New =AA&lt;/P&gt;
&lt;P&gt;for BB data set i want variable New =BB;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;please give me a solution.&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 15:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro/m-p/571250#M161141</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-04T15:19:34Z</dc:date>
    </item>
  </channel>
</rss>

