<?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: Removing a suffix from a variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278753#M269717</link>
    <description>&lt;P&gt;That code is pretty close, you need to make sure you case matches for the memname and name to generate the rename statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;
select cats(name,'=',scan(name, 1, '_'))
into :suffixlist
separated by ' '
from dictionary.columns
where libname = 'WORK' and upper(memname) = 'CONTAMINATION_C' and 'C' = scan(upper(name), 2, '_');
quit;

%put &amp;amp;suffixlist.;

data want;
set contamination_c;
rename &amp;amp;suffixlist.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 Jun 2016 17:32:54 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-20T17:32:54Z</dc:date>
    <item>
      <title>Removing a suffix from a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278746#M269715</link>
      <description>&lt;P&gt;I have a dataset where all the variables end in "_c" and I'd like to now remove the suffix.&lt;/P&gt;&lt;P&gt;However, I can't seem to find a way to do so. &amp;nbsp;I found some code below using the scan feature, but it doesn't seem to work.&lt;/P&gt;&lt;P&gt;Does anyone have an easy way to remove a suffix for all variables in a dataset?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data contamination_c;
input id_c name_c :$10. age_c gender_c diagnosis1_c diagnosis2_c;
datalines;
112 Albert 10 85 90 89
223 Joe 11 99 98 91
323 Jim 12 100 100 100
414 Sally 11 78 89 100
;
run;

proc sql noprint;
select cats(name,'=',scan(name, 1, '_'))
into :suffixlist
separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'contamination_c' and 'c' = scan(name, 2, '_');
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Jun 2016 17:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278746#M269715</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-06-20T17:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a suffix from a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278750#M269716</link>
      <description>&lt;P&gt;In dictionary.columns, MEMNAME is stored in uppercase.&amp;nbsp; Just change to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... and memname = 'CONTAMINATION_C' and ...&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 17:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278750#M269716</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-20T17:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a suffix from a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278753#M269717</link>
      <description>&lt;P&gt;That code is pretty close, you need to make sure you case matches for the memname and name to generate the rename statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;
select cats(name,'=',scan(name, 1, '_'))
into :suffixlist
separated by ' '
from dictionary.columns
where libname = 'WORK' and upper(memname) = 'CONTAMINATION_C' and 'C' = scan(upper(name), 2, '_');
quit;

%put &amp;amp;suffixlist.;

data want;
set contamination_c;
rename &amp;amp;suffixlist.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Jun 2016 17:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278753#M269717</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-20T17:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a suffix from a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278762#M269718</link>
      <description>&lt;P&gt;It almost worked! &amp;nbsp;All the variables changed except for variables with multiple underscores.&lt;/P&gt;&lt;P&gt;I have some variables with multiple underscores like not_enrolled_o and those variables for some reason are not dropping the "_o".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something else I need to add to the code to get it to recognize those variables with multiple underscores?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 17:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278762#M269718</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-06-20T17:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a suffix from a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278770#M269719</link>
      <description>&lt;P&gt;Then your SQL code needs to change. Take a look at how you're determining the variables to include.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 18:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278770#M269719</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-20T18:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a suffix from a variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278786#M269720</link>
      <description>&lt;P&gt;Ah, got it! &amp;nbsp;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 18:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-a-suffix-from-a-variable-name/m-p/278786#M269720</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-06-20T18:44:08Z</dc:date>
    </item>
  </channel>
</rss>

