<?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 help needed for sas macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312719#M270767</link>
    <description>&lt;P&gt;Dear SAS folks,&lt;/P&gt;
&lt;P&gt;I have more than 400 variables and want check the distribution of data for each of them. I developed a piece of code and found that it didn't work. The code is as following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro test;&lt;BR /&gt; %array abc{406} &amp;amp;var.;&lt;BR /&gt; %do i=1 %to 406;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table abc{i} as&lt;BR /&gt;select abc{i}&lt;BR /&gt;from monthend.final_201509&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
    <pubDate>Fri, 18 Nov 2016 20:18:52 GMT</pubDate>
    <dc:creator>HarryLiu</dc:creator>
    <dc:date>2016-11-18T20:18:52Z</dc:date>
    <item>
      <title>help needed for sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312719#M270767</link>
      <description>&lt;P&gt;Dear SAS folks,&lt;/P&gt;
&lt;P&gt;I have more than 400 variables and want check the distribution of data for each of them. I developed a piece of code and found that it didn't work. The code is as following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro test;&lt;BR /&gt; %array abc{406} &amp;amp;var.;&lt;BR /&gt; %do i=1 %to 406;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table abc{i} as&lt;BR /&gt;select abc{i}&lt;BR /&gt;from monthend.final_201509&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 20:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312719#M270767</guid>
      <dc:creator>HarryLiu</dc:creator>
      <dc:date>2016-11-18T20:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: help needed for sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312724#M270768</link>
      <description>&lt;P&gt;What do you mean by check the distribution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not something as simple as below. It generates all the summaries for all numeric variables in the dataset by default.&amp;nbsp;&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;proc univariate data=sashelp.class;
histogram;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro should be something like the following, but then you need to repeat whatever your analysis is for each table. So then you need another macro, which probably leads to another macro and you're down the road to code you can't reuse or understand.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro distribution(varlist=);
%let i=1;
%do %while (%scan(&amp;amp;varlist, &amp;amp;i) ^=%str());
%let var=%scan(&amp;amp;varlist, &amp;amp;i); 


proc sql;
create table &amp;amp;var as
select var
from monthend.final_201509
;
quit;
 
*Increment counter;
%let i=%eval(&amp;amp;i+1);
%end;
%mend;

%distribution( varlist=var1  var2 var3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 20:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312724#M270768</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-18T20:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: help needed for sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312728#M270769</link>
      <description>&lt;P&gt;Thanks Reeza a lot for your help. Your code works great. I am just curious why my code didn't work. My logic looks ok, but ....&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 20:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312728#M270769</guid>
      <dc:creator>HarryLiu</dc:creator>
      <dc:date>2016-11-18T20:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: help needed for sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312730#M270770</link>
      <description>&lt;P&gt;The logic is ok, in terms of concepts and pseudocode, but it's not valid SAS synax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The concept of creating a list and accessing the components one at a time is correct., but there is no concept of an array in macro's, so you can't refer to them as abc(i).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One&amp;nbsp;workaround is to create them as a list and then access one at a time using Scan to parse the list - which is what my solution implements. This is the same as your logic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 20:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312730#M270770</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-18T20:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: help needed for sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312732#M270771</link>
      <description>&lt;P&gt;Got it. Thanks again for detailed explanation.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 20:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312732#M270771</guid>
      <dc:creator>HarryLiu</dc:creator>
      <dc:date>2016-11-18T20:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: help needed for sas macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312739#M270772</link>
      <description>&lt;P&gt;I suspect that by "didn't work" in this case you meant there were errors. It is very helpful when discussing errors to post results from the LOG including the code and all error messages into an entry box opened by using the "run" icon in the forum menu. The position of some elements of the error messages is important and the entry box will preserve line formatting that the main box of the message loses.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 21:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-needed-for-sas-macro/m-p/312739#M270772</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-18T21:38:21Z</dc:date>
    </item>
  </channel>
</rss>

