<?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: Macro to automate checks on columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457242#M115907</link>
    <description>&lt;P&gt;If you search the forum here, you will probably find that this question has been addressed in ways that are shorter ... you don't need to name each variable individually.&amp;nbsp; However, if that doesn't appeal to you, the easiest route might be to divide the variables into separate data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data numerics (keep=_numeric_)&lt;/P&gt;
&lt;P&gt;characters (keep=_character_);&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you are guaranteed that every variable in one data set is numeric, and every variable in the other data set is character.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Apr 2018 11:55:38 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-04-25T11:55:38Z</dc:date>
    <item>
      <title>Macro to automate checks on columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457213#M115905</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have been given a massive table (800+ columns, over 200,000 rows)&amp;nbsp;with both character and numeric columns. I have been asked to find the proportion of missing data in each column, both overall and the average&amp;nbsp;annually,&amp;nbsp;and present the results in a table.&lt;/P&gt;&lt;P&gt;I have written macros for both numeric and character variables which will produce a row of the required data and append it to a table which will become the final table.&lt;/P&gt;&lt;P&gt;However, at the moment I will have to write all 800+ variable names into the macros one by one and then run it all at once.&lt;/P&gt;&lt;P&gt;Is there any way to write a macro that will run through the variables, decide if the current variable is numeric or character, and put it into the appropriate macro?&lt;BR /&gt;&lt;BR /&gt;For example, something like:&lt;BR /&gt;&lt;BR /&gt;%macro master_macro(dataset, date_var);&lt;/P&gt;&lt;P&gt;while(current variable&amp;nbsp;exists)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if the current variable is numeric do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my_numeric_macro(dataset, current variable, date_var);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my_character_macro(dataset, current variable, date_var);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;current variable =&amp;nbsp;next variable&lt;/P&gt;&lt;P&gt;%mend&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies for the sloppy pseudo code!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 11:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457213#M115905</guid>
      <dc:creator>Sean100</dc:creator>
      <dc:date>2018-04-25T11:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate checks on columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457242#M115907</link>
      <description>&lt;P&gt;If you search the forum here, you will probably find that this question has been addressed in ways that are shorter ... you don't need to name each variable individually.&amp;nbsp; However, if that doesn't appeal to you, the easiest route might be to divide the variables into separate data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data numerics (keep=_numeric_)&lt;/P&gt;
&lt;P&gt;characters (keep=_character_);&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you are guaranteed that every variable in one data set is numeric, and every variable in the other data set is character.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 11:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457242#M115907</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-25T11:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to automate checks on columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457262#M115911</link>
      <description>&lt;P&gt;You do not need macro at all.&amp;nbsp; Your problem can be broken down into two simple steps - get nmiss of number, get nmiss of characters, for instance, produce a report of missing numbers:&lt;/P&gt;
&lt;PRE&gt;proc means data=have nmiss;
  var _numeric_;
run;&lt;/PRE&gt;
&lt;P&gt;There are loads of very simple methodolgies for doing what you want, for instance:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-see-the-number-of-missing-values-and-patterns-of-missing-values-in-a-data-file/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-see-the-number-of-missing-values-and-patterns-of-missing-values-in-a-data-file/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use means, summary, freq, datastep, sql, etc.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 13:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-automate-checks-on-columns/m-p/457262#M115911</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-25T13:28:04Z</dc:date>
    </item>
  </channel>
</rss>

