<?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: Delete all variables from a datasets  that have all missing character valus in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914692#M360437</link>
    <description>&lt;P&gt;many thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;this solves my query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Feb 2024 14:11:20 GMT</pubDate>
    <dc:creator>Suki99</dc:creator>
    <dc:date>2024-02-06T14:11:20Z</dc:date>
    <item>
      <title>Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914535#M360380</link>
      <description>&lt;P&gt;hi all&lt;/P&gt;&lt;P&gt;I wanted to search across all my clinical datasets that have a certain string in&amp;nbsp; variable , ie i wanted to find out where that string 'LYNCH' was,&lt;/P&gt;&lt;P&gt;unfortunately in the process ive got a lot of variables that are redundant&amp;nbsp; ie have missing values, that i dont need and want to get rid of them in the final 'WANT ' dataset&lt;/P&gt;&lt;P&gt;, however i dont know of a quick&amp;nbsp; and efficient way to tell sas to delete/remove all variables that have missing values across all observations&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does anyone know how to do that please&amp;nbsp;&lt;/P&gt;&lt;P&gt;be indebted .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* find string / value across multiple datasets*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sort&lt;/STRONG&gt; data=sashelp.vcolumn&amp;nbsp;&amp;nbsp; out=test&amp;nbsp;&amp;nbsp; (keep= libname memname) nodupkey;&lt;/P&gt;&lt;P&gt;by libname memname;&lt;/P&gt;&lt;P&gt;where LIBNAME = 'SDTM'&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sql&lt;/STRONG&gt; noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;select 'SDTM.'||MEMNAME into :dslist separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp; from test;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;%put &amp;amp;dslist;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; WANT /*(where=(chvars{i}))*/;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set &amp;amp;dslist.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array chvars{*] _character_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do i = &lt;STRONG&gt;1&lt;/STRONG&gt; to dim(chvars);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index(upcase(chvars[i]),'LYNCH') then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Suki&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 16:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914535#M360380</guid>
      <dc:creator>Suki99</dc:creator>
      <dc:date>2024-02-05T16:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914537#M360381</link>
      <description>&lt;P&gt;This doesn't quite make sense to me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;ie i wanted to find out where that string 'LYNCH' was,&lt;/P&gt;
&lt;P&gt;unfortunately in the process ive got a lot of variables that are redundant&amp;nbsp; ie have missing values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a variable is being returned as having the string identified, it cannot be all missing at the same time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to remove observations or variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 16:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914537#M360381</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-05T16:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914540#M360382</link>
      <description>&lt;P&gt;hiya&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my set statement in the final statement calls in or sets about over&amp;nbsp; &amp;nbsp;24 datasets, so unwanted vars are coming from there.&lt;/P&gt;&lt;P&gt;so to answer your Q , i want to remove variables that just have missing values , but obviously keep the variable(s) that holds the string i want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 17:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914540#M360382</guid>
      <dc:creator>Suki99</dc:creator>
      <dc:date>2024-02-05T17:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914550#M360386</link>
      <description>&lt;P&gt;So you only want CHARACTER variables?&lt;/P&gt;
&lt;P&gt;What is the OUTPUT that you want?&amp;nbsp; Setting together all of the datasets together like that does not make much sense to me.&amp;nbsp; Why would you stack a DEMOG datasets with an AE dataset and a CONMED dataset?&amp;nbsp; That is going to create a strange checkboard pattern of missing values since the different datasets will be contributing different variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what do you mean by MISSING?&amp;nbsp; Do you mean variables that have no values at all in the source dataset?&amp;nbsp; Or variables that have no values when the dataset is subset to just the observations that have LYNCH somewhere?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 18:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914550#M360386</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-05T18:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914610#M360406</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well here's the %dropmiss macro that will likely work but as Tom indicates this is a bit of an abnormal request.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Source:&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings10/048-2010.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings10/048-2010.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Reference:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/28984570/dropmiss-sas" target="_blank"&gt;https://stackoverflow.com/questions/28984570/dropmiss-sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/******************/
options nomprint noSYMBOLGEN MLOGIC;
/****************************/
%macro DROPMISS( DSNIN /* name of input SAS dataset
    */
    , DSNOUT /* name of output SAS dataset
    */
    , NODROP= /* [optional] variables to be omitted from dropping even if
    they have only missing values */
    ) ;
    /* PURPOSE: To find both Character and Numeric the variables that have only
    missing values and drop them if
    * they are not in &amp;amp;NONDROP
    *
    * NOTE: if there are no variables in the dataset, produce no variables
    processing code
    *
    *
    * EXAMPLE OF USE:
    * %DROPMISS( DSNIN, DSNOUT )
    * %DROPMISS( DSNIN, DSNOUT, NODROP=A B C D--H X1-X100 )
    * %DROPMISS( DSNIN, DSNOUT, NODROP=_numeric_ )
    * %DROPMISS( DSNIN, DSNOUT, NOdrop=_character_ )
    */
    %local I ;
    %if "&amp;amp;DSNIN" = "&amp;amp;DSNOUT"
    %then %do ;
    %put /------------------------------------------------\ ;
    %put | ERROR from DROPMISS: | ;
    %put | Input Dataset has same name as Output Dataset. | ;
    %put | Execution terminating forthwith. | ;
    %put \------------------------------------------------/ ;
    %goto L9999 ;
    %end ;
    /*###################################################################*/
    /* begin executable code
    /*####################################################################/
    /*===================================================================*/
    /* Create dataset of variable names that have only missing values
    /* exclude from the computation all names in &amp;amp;NODROP
    /*===================================================================*/
    proc contents data=&amp;amp;DSNIN( drop=&amp;amp;NODROP ) memtype=data noprint out=_cntnts_( keep=
    name type ) ; run ;
    %let N_CHAR = 0 ;
    %let N_NUM = 0 ;
    data _null_ ;
    set _cntnts_ end=lastobs nobs=nobs ;

    if nobs = 0 then stop ;
    n_char + ( type = 2 ) ;
    n_num + ( type = 1 ) ;
    /* create macro vars containing final # of char, numeric variables */
    if lastobs
    then do ;
    call symput( 'N_CHAR', left( put( n_char, 5. ))) ;
    call symput( 'N_NUM' , left( put( n_num , 5. ))) ;
    end ;
    run ;
    /*===================================================================*/
    /* if there are no variables in dataset, stop further processing
    /*===================================================================*/
    %if %eval( &amp;amp;N_NUM + &amp;amp;N_CHAR ) = 0
    %then %do ;
    %put /----------------------------------\ ;
    %put | ERROR from DROPMISS: | ;
    %put | No variables in dataset. | ;
    %put | Execution terminating forthwith. | ;
    %put \----------------------------------/ ;
    %goto L9999 ;
    %end ;
    /*===================================================================*/
    /* put global macro names into global symbol table for later retrieval
    /*===================================================================*/
    %LET NUM0 =0;
    %LET CHAR0 = 0;
    %IF &amp;amp;N_NUM &amp;gt;0 %THEN %DO;
    %do I = 1 %to &amp;amp;N_NUM ;
    %global NUM&amp;amp;I ;
    %end ;
    %END;
    %if &amp;amp;N_CHAR &amp;gt; 0 %THEN %DO;
    %do I = 1 %to &amp;amp;N_CHAR ;
    %global CHAR&amp;amp;I ;
    %end ;
    %END;
    /*===================================================================*/
    /* create macro vars containing variable names
    /* efficiency note: could compute n_char, n_num here, but must declare macro names
    to be
    global b4 stuffing them
    /*
    /*===================================================================*/
    proc sql noprint ;
    %if &amp;amp;N_CHAR &amp;gt; 0 %then %str( select name into :CHAR1 - :CHAR&amp;amp;N_CHAR from
    _cntnts_ where type = 2 ; ) ;
    %if &amp;amp;N_NUM &amp;gt; 0 %then %str( select name into :NUM1 - :NUM&amp;amp;N_NUM from
    _cntnts_ where type = 1 ; ) ;
    quit ;
    /*===================================================================*/
    /* Determine the variables that are missing

    /*
    /*===================================================================*/
    %IF &amp;amp;N_CHAR &amp;gt; 1 %THEN %DO;
    %let N_CHAR_1 = %EVAL(&amp;amp;N_CHAR - 1);
    %END;
    Proc sql ;
    select %do I= 1 %to &amp;amp;N_NUM; max (&amp;amp;&amp;amp;NUM&amp;amp;I) , %end; %IF &amp;amp;N_CHAR &amp;gt; 1 %THEN %DO;
    %do I= 1 %to &amp;amp;N_CHAR_1; max(&amp;amp;&amp;amp;CHAR&amp;amp;I), %END; %end; MAX(&amp;amp;&amp;amp;CHAR&amp;amp;N_CHAR)
    into
    %do I= 1 %to &amp;amp;N_NUM; :NUMMAX&amp;amp;I , %END; %IF &amp;amp;N_CHAR &amp;gt; 1 %THEN %DO;
    %do I= 1 %to &amp;amp;N_CHAR_1; :CHARMAX&amp;amp;I,%END; %END; :CHARMAX&amp;amp;N_CHAR
    from &amp;amp;DSNIN;
    quit;
    /*===================================================================*/
    /* initialize DROP_NUM, DROP_CHAR global macro vars
    /*===================================================================*/
    %let DROP_NUM = ;
    %let DROP_CHAR = ;
    %if &amp;amp;N_NUM &amp;gt; 0 %THEN %DO;
    DATA _NULL_;
    %do I = 1 %to &amp;amp;N_NUM ;
    %IF &amp;amp;&amp;amp;NUMMAX&amp;amp;I =. %THEN %DO;
    %let DROP_NUM = &amp;amp;DROP_NUM %qtrim( &amp;amp;&amp;amp;NUM&amp;amp;I ) ;
    %END;
    %end ;
    RUN;
    %END;
    %IF &amp;amp;N_CHAR &amp;gt; 0 %THEN %DO;
    DATA _NULL_;
    %do I = 1 %to &amp;amp;N_CHAR ;
    %IF "%qtrim(&amp;amp;&amp;amp;CHARMAX&amp;amp;I)" eq "" %THEN %DO;
    %let DROP_CHAR = &amp;amp;DROP_CHAR %qtrim( &amp;amp;&amp;amp;CHAR&amp;amp;I ) ;
    %END;
    %end ;
    RUN;
    %END;
    /*===================================================================*/
    /* Create output dataset
    /*===================================================================*/
    data &amp;amp;DSNOUT ;
    %if &amp;amp;DROP_CHAR ^= %then %str(DROP &amp;amp;DROP_CHAR ; ) ; /* drop char variables
    that
    have only missing values */
    %if &amp;amp;DROP_NUM ^= %then %str(DROP &amp;amp;DROP_NUM ; ) ; /* drop num variables
    that
    have only missing values */
    set &amp;amp;DSNIN ;
    %if &amp;amp;DROP_CHAR ^= or &amp;amp;DROP_NUM ^= %then %do;

    %put /----------------------------------\ ;
    %put | Variables dropped are &amp;amp;DROP_CHAR &amp;amp;DROP_NUM | ;
    %put \----------------------------------/ ;
    %end;
    %if &amp;amp;DROP_CHAR = and &amp;amp;DROP_NUM = %then %do;
    %put /----------------------------------\ ;
    %put | No variables are dropped |;
    %put \----------------------------------/ ;
    %end;
    run ;
    %L9999:
%mend DROPMISS ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Mon, 05 Feb 2024 23:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914610#M360406</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-05T23:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914641#M360419</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Delete-variables-with-90-missing-values/m-p/859816" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Delete-variables-with-90-missing-values/m-p/859816&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro drop_vars(dsn=,pct=);&lt;BR /&gt;proc transpose data=&amp;amp;dsn.(obs=0) out=vname;&lt;BR /&gt;var _all_;&lt;BR /&gt;run;&lt;BR /&gt;data _null_;&lt;BR /&gt;set vname end=last;&lt;BR /&gt;if _n_=1 then call execute('proc sql;create table n_miss as select ');&lt;BR /&gt;call execute(catx(' ','nmiss(',_name_,') as ',_name_));&lt;BR /&gt;if last then call execute("from &amp;amp;dsn.;quit;");&lt;BR /&gt;else call execute(',');&lt;BR /&gt;run;&lt;BR /&gt;proc transpose data=n_miss out=n_miss2;&lt;BR /&gt;var _all_;&lt;BR /&gt;run;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select count(*) into :nobs from &amp;amp;dsn.;&lt;BR /&gt;select _NAME_ into :drops separated by ',' from n_miss2 where col1/&amp;amp;nobs. &amp;gt;= &amp;amp;pct. ;&lt;BR /&gt;alter table &amp;amp;dsn. drop &amp;amp;drops.;&lt;BR /&gt;quit;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;set sashelp.heart;&lt;BR /&gt;run;&lt;BR /&gt;/*&lt;BR /&gt;dsn is the dataset you want modify&lt;BR /&gt;pct is the percent of missing you want to drop&lt;BR /&gt;*/&lt;BR /&gt;%drop_vars(dsn=have,pct=1)&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 06:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914641#M360419</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-06T06:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all variables from a datasets  that have all missing character valus</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914692#M360437</link>
      <description>&lt;P&gt;many thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;this solves my query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 14:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-variables-from-a-datasets-that-have-all-missing/m-p/914692#M360437</guid>
      <dc:creator>Suki99</dc:creator>
      <dc:date>2024-02-06T14:11:20Z</dc:date>
    </item>
  </channel>
</rss>

