<?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 select  rows with column value not in  a macro list? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492961#M129655</link>
    <description>handle variable is quite difficult sometime in sas</description>
    <pubDate>Thu, 06 Sep 2018 11:18:03 GMT</pubDate>
    <dc:creator>Geo-</dc:creator>
    <dc:date>2018-09-06T11:18:03Z</dc:date>
    <item>
      <title>how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492935#M129636</link>
      <description>&lt;P&gt;how to select&amp;nbsp; rows with column value not in&amp;nbsp; a macro list?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;%macro changeName(&amp;amp;var_list);&lt;BR /&gt;proc sql noprint;&lt;BR /&gt; select cats(name,'=',case when type='num' then 'XN_' else 'XC_' end,name) into :renames separated by ' '&lt;BR /&gt; from dictionary.columns where libname='SASHELP' and memname='CLASS' and name not in(&amp;amp;var_list);&lt;BR /&gt;%put &amp;amp;renames;&lt;BR /&gt;data test;&lt;BR /&gt; set sashelp.class;&lt;BR /&gt; rename &amp;amp;renames;&lt;BR /&gt;run;&lt;BR /&gt;%mend();&lt;BR /&gt;&lt;BR /&gt;%changeName(Age,Name);



&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 10:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492935#M129636</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-09-06T10:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492937#M129638</link>
      <description>&lt;P&gt;Take my suggestion from the other thread, and expand it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vcolumn (where=(libname="LIBRARY" and memname = "DATASET")) end=eof;
length prefix $3;
if _n_ = 1 then call execute("
  proc datasets library=LIBRARY nolist;
  modify DATASET;
  rename
");
if name not in (&amp;amp;var_list.)
then do;
  if type = 'char'
  then prefix = "XC_";
  else prefix = "XN_";
  call execute(trim(name !! '=' !! prefix !! trim(name) !! ' '));
end;
if eof then call execute("
  ;
  quit;
");
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Edit: corrected in-list&lt;/EM&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 10:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492937#M129638</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-06T10:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492938#M129639</link>
      <description>&lt;P&gt;Note that I prefer to use proc datasets for the renaming action because it does not rewrite the whole dataset, only the header page.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 10:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492938#M129639</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-06T10:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492940#M129641</link>
      <description>&lt;P&gt;What does num_list look like?&amp;nbsp; What is the end goal of the code?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If num_list is a space delimited list then there was this exact post yesterday:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492585#M129465" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Want-to-quote-the-string-in-macro-variable/m-p/492585#M129465&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, depending on your process its likely you don't need any of this code.&amp;nbsp; Also, again, please provide full information, test data, required output.&amp;nbsp; Its written under the Post question button, and saves us having to guess.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 10:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492940#M129641</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-06T10:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492944#M129645</link>
      <description>I have updated the case,would you mind check if it's clear to you</description>
      <pubDate>Thu, 06 Sep 2018 10:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492944#M129645</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-09-06T10:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492948#M129648</link>
      <description>&lt;P&gt;Thanks, after looking at that, the simplest method is probably:&lt;/P&gt;
&lt;PRE&gt;%macro changename(dsin=,dsout=,varlist=);

  data &amp;amp;dsout.;
    set &amp;amp;dsin.;
    rename 
    %do i=1 %to %sysfunc(countw(&amp;amp;varlist.,|));
      %scan(&amp;amp;varlist.,&amp;amp;i.,|)=%scan(&amp;amp;varlist.,&amp;amp;i.,|)_want 
    %end;
    ;
  run;
  
%mend changename;

%changename(dsin=sashelp.class,dsout=want,varlist=age|name);&lt;/PRE&gt;
&lt;P&gt;I use the | to delimit rather than a comma as the comma is used to divide paramters, so best avoided.&amp;nbsp; I show as datastep here, but once you understand the above code, proc datasets should be used as that is quicker.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit, the same thing but with proc datasets, modifying in place:&lt;/P&gt;
&lt;PRE&gt;%macro changename(dsin=,varlist=);

  proc datasets lib=work nolist;
    modify &amp;amp;dsin.;
      rename 
        %do i=1 %to %sysfunc(countw(&amp;amp;varlist.,|));
           %scan(&amp;amp;varlist.,&amp;amp;i.,|)=%scan(&amp;amp;varlist.,&amp;amp;i.,|)_want 
        %end;
      ;
  quit;
  run;
       
%mend changename;

data want;
  set sashelp.class;
run;

%changename(dsin=want,varlist=age|name);&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 10:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492948#M129648</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-06T10:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492952#M129649</link>
      <description>actually I want to change the names which are not in the macro variables..</description>
      <pubDate>Thu, 06 Sep 2018 10:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492952#M129649</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-09-06T10:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492959#M129654</link>
      <description>&lt;P&gt;Bit more complicated then:&lt;/P&gt;
&lt;PRE&gt;%macro changename(dsin=,varlist=);

  proc sql;
    select cats(name,"=",name,"_want")
    into :tmp separated by " "
    from dictionary.columns
    where libname="WORK"
      and memname=upcase("&amp;amp;dsin.")
      and upcase(name) not in (
    %do i=1 %to %sysfunc(countw(&amp;amp;varlist.,|));
      %sysfunc(quote(%sysfunc(upcase(%scan(&amp;amp;varlist.,&amp;amp;i.,|)))))
    %end; 
      );
  quit;

  proc datasets lib=work nolist;
    modify &amp;amp;dsin.;
      rename &amp;amp;tmp.;
  quit;
  run;

  
%mend changename;

data want;
  set sashelp.class;
run;

%changename(dsin=want,varlist=age|name);&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Sep 2018 10:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492959#M129654</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-06T10:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492961#M129655</link>
      <description>handle variable is quite difficult sometime in sas</description>
      <pubDate>Thu, 06 Sep 2018 11:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492961#M129655</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-09-06T11:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to select  rows with column value not in  a macro list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492968#M129658</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184018"&gt;@Geo-&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;handle variable is quite difficult sometime in sas&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It should be a rather rare occurence. Data is fluent, while structure should be fixed. Changing column names are usually an indicator for poor design.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Sep 2018 11:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492968#M129658</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-06T11:46:04Z</dc:date>
    </item>
  </channel>
</rss>

