<?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: Question about a SAS macro to calculate missing data percentage of each variable in the data set in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509858#M15809</link>
    <description>&lt;P&gt;There is no blank space at the end of &amp;amp;ALLVARS, so the FIND function can't locate one to determine when the last variable name ends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider modifying here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;allvars=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%substr&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;allvars.,&amp;amp;firstspace.&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;+1&lt;/FONT&gt;&lt;/STRONG&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;firstspace=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(find(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;%str(&lt;/FONT&gt;&lt;/STRONG&gt;&amp;amp;allvars.&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;( )));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The first change removes the leading blank from &amp;amp;ALLVARS.&amp;nbsp; Then the second change adds a blank to the end of &amp;amp;ALLVARS.&amp;nbsp; (Not sure that the first change is required, but you can test it and report back to the group.)&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Nov 2018 13:35:23 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-11-02T13:35:23Z</dc:date>
    <item>
      <title>Question about a SAS macro to calculate missing data percentage of each variable in the data set</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509849#M15807</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I found a macro&amp;nbsp;in the forum to calculate the missing data percentage for each variable in the data set. I tried it and it works, but for some reason the last variable in the data set will be get rid of, I wonder how to fix this macro. Is there anybody can help? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;1) Macro&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; missing_data(library=,dataset=,xoutdataset=);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;select name into :allvars separated by &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;" "&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; from dictionary.columns&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;where libname=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"%upcase(&amp;amp;library.)"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; and memname=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"%upcase(&amp;amp;dataset.)"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;create table &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;xoutdataset.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; firstspace=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(find(&amp;amp;allvars.,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;( )));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;firstspace.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; var=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%substr&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;allvars.,1,&amp;amp;firstspace.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;sum(missing(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;var.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))/count(*) as &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;var.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; allvars=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%substr&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;allvars.,&amp;amp;firstspace.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; firstspace=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(find(&amp;amp;allvars.,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;( )));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Y'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; as done_successfully&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;from &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;library.&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;dataset.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; missing_data;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;missing_data&lt;/I&gt;&lt;/STRONG&gt;(library=sashelp,dataset=class,xoutdataset=outfile);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 2) The output variable list after macro used:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Name Sex Age Height done_successfully&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 3) The variable list in the data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Name Sex Age Height Weight&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Compare 2) and 3), we can see the weight variable&amp;nbsp;is gone after using the macro. I wonder how this macro be fixed to include every variables in the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jade&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 13:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509849#M15807</guid>
      <dc:creator>Jade_SAS</dc:creator>
      <dc:date>2018-11-02T13:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: Question about a SAS macro to calculate missing data percentage of each variable in the data set</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509854#M15808</link>
      <description>&lt;P&gt;Something in the looping over the variables gets screwed up by this code. I will leave it to others to figure out exactly where the error is (if understanding the exact error is of interest). However, the code below doesn't have this problem&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro missing_data(library=,dataset=,xoutdataset=);
    proc sql noprint;
        select name into :allvars separated by " " from dictionary.columns
        where libname="%upcase(&amp;amp;library.)" and 
        memname="%upcase(&amp;amp;dataset.)";
    quit;
    proc sql noprint;
        create table &amp;amp;xoutdataset. as select
        %do i=1 %to %sysfunc(countw(&amp;amp;allvars));
              %let var=%scan(&amp;amp;allvars,&amp;amp;i,%str( ));
              sum(missing(&amp;amp;var.))/count(*) as &amp;amp;var. 
              %if &amp;amp;i&amp;lt;%sysfunc(countw(&amp;amp;allvars)) %then , ;
        %end;
        from &amp;amp;library..&amp;amp;dataset.;
    quit;
%mend missing_data;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 13:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509854#M15808</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T13:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Question about a SAS macro to calculate missing data percentage of each variable in the data set</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509858#M15809</link>
      <description>&lt;P&gt;There is no blank space at the end of &amp;amp;ALLVARS, so the FIND function can't locate one to determine when the last variable name ends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider modifying here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;allvars=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%substr&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;allvars.,&amp;amp;firstspace.&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;+1&lt;/FONT&gt;&lt;/STRONG&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;firstspace=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(find(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;%str(&lt;/FONT&gt;&lt;/STRONG&gt;&amp;amp;allvars.&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;( )));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The first change removes the leading blank from &amp;amp;ALLVARS.&amp;nbsp; Then the second change adds a blank to the end of &amp;amp;ALLVARS.&amp;nbsp; (Not sure that the first change is required, but you can test it and report back to the group.)&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 13:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509858#M15809</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-02T13:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Question about a SAS macro to calculate missing data percentage of each variable in the data set</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509863#M15810</link>
      <description>&lt;P&gt;Thank you Paige!&amp;nbsp;Your macro worked!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 13:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509863#M15810</guid>
      <dc:creator>Jade_SAS</dc:creator>
      <dc:date>2018-11-02T13:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Question about a SAS macro to calculate missing data percentage of each variable in the data set</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509865#M15811</link>
      <description>&lt;P&gt;Try this code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
 call missing(age ,sex);
run;

/*firstly get variable name*/
proc transpose data=have(obs=0) out=vname;
var _all_;
run;
/*then know  missing percent*/
proc sql noprint;
select catx(' ','nmiss(',_name_,')/count(*) as',_name_) into :vnames separated by ','
from vname;
create table want as
select &amp;amp;vnames from have;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 13:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509865#M15811</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-02T13:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Question about a SAS macro to calculate missing data percentage of each variable in the data set</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509866#M15812</link>
      <description>&lt;P&gt;When you use %substr, the resulting macro variable has no blanks for padding (as opposed to what you have in a data step), so the resulting value for firstchar is zero when there's one item left.&lt;/P&gt;
&lt;P&gt;The way the loop is built, someone out-thunk him/herself&amp;nbsp; when working around the non-existent %countw() function.&lt;/P&gt;
&lt;P&gt;The proper method for such loops has been posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;: use %sysfunc(countw()) and a simple iterative do loop.&lt;/P&gt;
&lt;P&gt;And support my suggestion for the introduction of a %countw macro function:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Macro-equivalent-for-countw/idi-p/409066" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Macro-equivalent-for-countw/idi-p/409066&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 13:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Question-about-a-SAS-macro-to-calculate-missing-data-percentage/m-p/509866#M15812</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-02T13:44:37Z</dc:date>
    </item>
  </channel>
</rss>

