<?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: How to delete variables with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593535#M170342</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290079"&gt;@Birgithj&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;For a task as simple as this, I see no reason to rewrite the original data set even once, let alone twice. Just auto-define a view VHAVE with the unneeded variables dropped and refer to it instead of HAVE in the processing downstream:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                            
  input VarA VarB VarC VarD VarE VarF ;                                                
  cards ;                                                                              
1 2 3 1 2 3                                                                            
1 2 3 1 2 3                                                                            
1 2 3 1 2 .                                                                            
1 2 3 . 2 .                                                                            
1 2 3 1 2 3                                                                            
1 . 3 1 . 3                                                                            
1 . 3 1 . 3                                                                            
;                                                                                      
run ;                                                                                  
                                                                                       
data _null_ ;                                                                          
  do until (z) ;                                                                       
    set have end = z ;                                                                 
    array v var: ;                                                                     
    length _d $ 32767 ;                                                                
    do over v ;                                                                        
      if missing (v) and findw (_d, vname(v)) = 0 then _d = catx (" ", _d, vname (v)) ;
    end ;                                                                              
  end ;                                                                                
  call execute (cats ("data vhave/view=vhave; set have(drop=", _d, "); run;")) ;       
run ;                                                                                  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you read VHAVE instead of HAVE, you'll have what you need. Note that the entire resource consumption with this method amounts to a &lt;EM&gt;single read&lt;/EM&gt; through HAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Oct 2019 20:24:23 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-10-02T20:24:23Z</dc:date>
    <item>
      <title>How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593273#M170242</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am hoping you can help me. I have a large set of variables, where some of the variables have missing values (small example shown below). I only want to keep variables where there are no missing values, e.g. I need to delete variable B below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I delete all variables with missing values?&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;Var A&lt;/TD&gt;&lt;TD&gt;Var B&lt;/TD&gt;&lt;TD&gt;Var C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 09:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593273#M170242</guid>
      <dc:creator>Birgithj</dc:creator>
      <dc:date>2019-10-02T09:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593284#M170244</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input VarA VarB VarC;
datalines;
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 . 3
1 . 3
;

proc transpose data=have out=temp;
    var _numeric_;
run;

data temp2;
    set temp;
    if nmiss(of col:)=0;
run;

proc transpose data=temp2 out=want(drop=_:);
    id _name_;
    var col:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2019 10:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593284#M170244</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-02T10:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593285#M170245</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290079"&gt;@Birgithj&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can adapt a technique that has been suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;for a &lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-char-missing-values-in-a-dataset-and-remove-the-features/m-p/593006#M170116" target="_blank" rel="noopener"&gt;similar question&lt;/A&gt; yesterday, e.g., like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output nlevels=_nlev(keep=tablevar nmisslevels);
proc freq data=have nlevels;
tables _all_ / noprint;
run;

data _null_;
call execute('data want; set have; drop _n_');
do until(last);
  set _nlev end=last;
  if nmisslevels then call execute(tablevar);
end;
call execute('; run;');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(This works for numeric and character variables.)&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 10:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593285#M170245</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-02T10:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593286#M170246</link>
      <description>&lt;P&gt;Here is a way to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Var_A	Var_B	Var_C Var_D;
cards;
1	2	3  1
1	2	3  .
1	2	3  .
1	2	3  .
1	2	3  .
1	.	3  .
1	.	3  .
run;

%let inds=WORK.HAVE;
data _NULL_;
  length missvars $2000;
  dsid=open("&amp;amp;inds");
  do i=1 to attrn(dsid,'nvars');
    var=varname(dsid,i);
	dsid2=open(catx(' ',"&amp;amp;inds(where=(",var,'is null))'));
	if fetch(dsid2)=0 then
	  call catx(' ',missvars,var);
	dsid2=close(dsid2);
	end;
  call symputx('missvars',missvars);
run;
%put &amp;amp;missvars;

Data want;
  set have(drop=&amp;amp;missvars);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2019 10:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593286#M170246</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-02T10:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593293#M170248</link>
      <description>&lt;P&gt;Thank you so much! This solved my problem &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 10:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593293#M170248</guid>
      <dc:creator>Birgithj</dc:creator>
      <dc:date>2019-10-02T10:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593535#M170342</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290079"&gt;@Birgithj&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;For a task as simple as this, I see no reason to rewrite the original data set even once, let alone twice. Just auto-define a view VHAVE with the unneeded variables dropped and refer to it instead of HAVE in the processing downstream:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                            
  input VarA VarB VarC VarD VarE VarF ;                                                
  cards ;                                                                              
1 2 3 1 2 3                                                                            
1 2 3 1 2 3                                                                            
1 2 3 1 2 .                                                                            
1 2 3 . 2 .                                                                            
1 2 3 1 2 3                                                                            
1 . 3 1 . 3                                                                            
1 . 3 1 . 3                                                                            
;                                                                                      
run ;                                                                                  
                                                                                       
data _null_ ;                                                                          
  do until (z) ;                                                                       
    set have end = z ;                                                                 
    array v var: ;                                                                     
    length _d $ 32767 ;                                                                
    do over v ;                                                                        
      if missing (v) and findw (_d, vname(v)) = 0 then _d = catx (" ", _d, vname (v)) ;
    end ;                                                                              
  end ;                                                                                
  call execute (cats ("data vhave/view=vhave; set have(drop=", _d, "); run;")) ;       
run ;                                                                                  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you read VHAVE instead of HAVE, you'll have what you need. Note that the entire resource consumption with this method amounts to a &lt;EM&gt;single read&lt;/EM&gt; through HAVE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 20:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593535#M170342</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-02T20:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593735#M170456</link>
      <description>&lt;P&gt;Do not use PROC TRANSPOSE if you have a big table. ( EDITED )&lt;/P&gt;
&lt;PRE&gt;data have;
input VarA VarB VarC;
datalines;
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 . 3
1 . 3
;
ods select none;
ods output nlevels=temp;
proc freq data=have nlevels ;
table _all_;
run;
ods select all;

proc sql;
select tablevar into : drop separated by ' '
 from temp
  where nmisslevels&amp;gt;0;
quit;

data want;
 set have;
 drop &amp;amp;drop;
run;
proc print;run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 12:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593735#M170456</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-04T12:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593838#M170503</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;"&lt;SPAN&gt;Do not use PROC TRANSPOSE if you have a big table."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Agree; TRANSPOSE is quite memory-hungry. Also, if better performance is desired, MEANS does much better than FREQ with NLEVELS&amp;nbsp;(and that without the burden of using ODS), particularly if the VAR variables are numerous; e,g.:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means noprint data = have ;                                               
  var var: ;                                                                   
  output out = temp (drop = _:) nmiss=;                                        
run ;                                                                          
                                                                               
data _null_ ;                                                                  
  set temp ;                                                                   
  array nn _numeric_ ;                                                         
  call symputx ("drop", "") ;                                                  
  do over nn ;                                                                 
    if nn then call symputx ("drop", catx (" ", symget ("drop"), vname (nn))) ;
  end ;                                                                        
run ;                                                                          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Kind regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Paul D.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;p.s. As a side note, in your SQL, TableVar should be used instead of NLevels, or else the DATA step consuming the DROP macro variable won't produce the desired result (and bomb to boot on the attempt to use an invalid SAS name in the DROP list).&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As a side note: Your last step will bomb on the DROP statement because in the preceding SQL you select NLevels, while it should be TableVar instead.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 18:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/593838#M170503</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-03T18:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete variables with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/594075#M170615</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;Thanks point out that error. it has been fixed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you said PROC MEANS can't handle character variable.&lt;/P&gt;
&lt;P&gt;Another Alternative way is using PROC SQL, but need some more code (I did't post it ), I believe SQL would have faster speed .&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 12:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-variables-with-missing-values/m-p/594075#M170615</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-04T12:23:22Z</dc:date>
    </item>
  </channel>
</rss>

