<?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 Proc Freq for missing values trouble shooting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921714#M362957</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with character and numeric variables (var1, var2, ....) and one of the variables is called 'fy' which takes on the character values of '2022','2023', and '2024'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a dataset as follows below. The value 0.7 ,for example, represents the percentage of values of var1 that is missing or blank. In this case, 70% of var1 values in the dataset is missing or blank. Code should be able to handle whether var1 is character or numeric. Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fy2022&lt;/TD&gt;&lt;TD&gt;fy2023&lt;/TD&gt;&lt;TD&gt;fy2024&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;0.7&lt;/TD&gt;&lt;TD&gt;0.65&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;0.4&lt;/TD&gt;&lt;TD&gt;0.35&lt;/TD&gt;&lt;TD&gt;0.3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;0.45&lt;/TD&gt;&lt;TD&gt;0.4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;0.35&lt;/TD&gt;&lt;TD&gt;0.3&lt;/TD&gt;&lt;TD&gt;0.25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var5&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;0.55&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using proc freq data=out.mydataset;&lt;/P&gt;&lt;P&gt;tables _all_/list missing;&lt;/P&gt;&lt;P&gt;format _character_ $missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _numeric_ missing.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2024 15:28:57 GMT</pubDate>
    <dc:creator>aidant01</dc:creator>
    <dc:date>2024-03-25T15:28:57Z</dc:date>
    <item>
      <title>Proc Freq for missing values trouble shooting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921714#M362957</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with character and numeric variables (var1, var2, ....) and one of the variables is called 'fy' which takes on the character values of '2022','2023', and '2024'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a dataset as follows below. The value 0.7 ,for example, represents the percentage of values of var1 that is missing or blank. In this case, 70% of var1 values in the dataset is missing or blank. Code should be able to handle whether var1 is character or numeric. Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;fy2022&lt;/TD&gt;&lt;TD&gt;fy2023&lt;/TD&gt;&lt;TD&gt;fy2024&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;0.7&lt;/TD&gt;&lt;TD&gt;0.65&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;0.4&lt;/TD&gt;&lt;TD&gt;0.35&lt;/TD&gt;&lt;TD&gt;0.3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;0.45&lt;/TD&gt;&lt;TD&gt;0.4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;0.35&lt;/TD&gt;&lt;TD&gt;0.3&lt;/TD&gt;&lt;TD&gt;0.25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;var5&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;0.55&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using proc freq data=out.mydataset;&lt;/P&gt;&lt;P&gt;tables _all_/list missing;&lt;/P&gt;&lt;P&gt;format _character_ $missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _numeric_ missing.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 15:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921714#M362957</guid>
      <dc:creator>aidant01</dc:creator>
      <dc:date>2024-03-25T15:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq for missing values trouble shooting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921718#M362958</link>
      <description>&lt;P&gt;As you have found out the OUT= option only works for one variable. Plus your code doesn't show any attempt to cross the variables with the FY variable.&lt;/P&gt;
&lt;P&gt;To get results for each level of FY your tables statement would have to look like:&lt;/P&gt;
&lt;PRE&gt;tables fy *(list of variables) /missing;&lt;/PRE&gt;
&lt;P&gt;If you use fy *_character_&amp;nbsp; since you say Fy is character (and why a year is ever character baffles me) or fy*_all_, you will get FY crossed with itself. So be prepared to handle that.&lt;/P&gt;
&lt;P&gt;This will create a summary data set:&lt;/P&gt;
&lt;PRE&gt;ods output crosstabfreqs=mycrosstab;
proc freq data=example;
tables FY* _all_/list missing;
format _character_ $missing.
      _numeric_ missing.;
run;&lt;/PRE&gt;
&lt;P&gt;With two-way tables like this and what you want to find you would be looking the _type_=11 rows of data.&lt;/P&gt;
&lt;P&gt;You would likely pass the output data set through a data step to filter records and then use that as input to something else IF you actually need a data set then Proc transpose with the FY variable as an ID variable (BY TABLE) or one of Proc Report or Tabulate.&lt;/P&gt;
&lt;P&gt;Without knowing what your MISSING formats look like I can't suggest exact code but you would be looking for values of the format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR instead of your raw data into proc freq I would probably reshape the whole data set to add a variable name and a missing/nonmissing value indicator (no format needed) and summarize that set.&lt;/P&gt;
&lt;PRE&gt;data helpful;
   set out.mydataset;
   array c(*) _character_;
   array v(*) _numeric_;
   do i= 1 to dim(c);
      name=vname(c[i]);
      missing = missing(c[i]);
      if upcase(name) ne 'FY' then output;
   end;
   do i= 1 to dim(v);
      name=vname(v[i]);
      missing = missing(v[i]);
   end;
   keep FY name missing;
run;

proc tabulate data=helpful;
   class fy name;
   var missing
   table name,
         fy*name*mean=' '
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Data sets that are wide with actual values in data set names are poor choices for further processing.&lt;/P&gt;
&lt;P&gt;If you need a data set with the values:&lt;/P&gt;
&lt;PRE&gt;proc summary data=helpful nway;
   class fy name;
   var missing;
   output out=want (drop= _:) mean=;
run;&lt;/PRE&gt;
&lt;P&gt;Both the Tabulate and Summary code use the result of the mean of a 1/0 coded numeric value is the percentage of 1 values, which what the MISSING function returns in the data step building helpful. Note that MISSING is one of the few functions that works with both numeric and character values.&lt;/P&gt;
&lt;P&gt;This also does not create FY crossed with itself results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 16:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921718#M362958</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-25T16:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq for missing values trouble shooting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921733#M362966</link>
      <description>&lt;P&gt;With a temporary modification of the dataset, a PROC TABULATE might be what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data need / view=need;
  set have;
  array v var1-var6;
  do over v;
    v=nmiss(v);  /*Missing==&amp;gt;1,  otherwise==&amp;gt;.) */
  end;
run;

proc tabulate data=need noseps ;
  class FY;
  var var1-var6;
  tables (var1-var6)*(mean=' ')*f=percent8.2
        , FY all='All Years' / rts=12;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2024 19:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921733#M362966</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-25T19:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Freq for missing values trouble shooting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921770#M362982</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
call streaminit(123);
do fy='2022','2023','2024';
  do obs=1 to 100;
     var1=rand('uniform'); if rand('uniform')&amp;lt;0.1 then call missing(var1);
     var2=rand('uniform'); if rand('uniform')&amp;lt;0.2 then call missing(var2);
     var3=rand('uniform'); if rand('uniform')&amp;lt;0.3 then call missing(var3);
     var4=rand('uniform'); if rand('uniform')&amp;lt;0.4 then call missing(var4);
     var5=rand('uniform'); if rand('uniform')&amp;lt;0.5 then call missing(var5);
	 output;
  end;
end;
run;



proc sql;
create table temp as
select fy,
       nmiss(var1)/(select count(*) from have where fy=a.fy) as var1,
	   nmiss(var2)/(select count(*) from have where fy=a.fy) as var2,
	   nmiss(var3)/(select count(*) from have where fy=a.fy) as var3,
	   nmiss(var4)/(select count(*) from have where fy=a.fy) as var4,
	   nmiss(var5)/(select count(*) from have where fy=a.fy) as var5
 from have as a
  group by fy;
quit;
proc transpose data=temp out=want prefix=fy;
id fy;
var var1-var5;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2024 03:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Freq-for-missing-values-trouble-shooting/m-p/921770#M362982</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-26T03:04:18Z</dc:date>
    </item>
  </channel>
</rss>

