<?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 remove suffix from variables in a column? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855285#M338060</link>
    <description>&lt;P&gt;Assuming you mean that you have a DATASET that has VARIABLES named X_RATIO, Y_RATIO etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the answer is No. If you want to rename variable you need to use a rename statement or a rename= dataset option. But that does not mean you have to TYPE them out yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get the list of variables that match your pattern and generate the OLD=NEW pairs into a macro variable. Then use the macro variable to generate the RENAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the data is named HAVE in the WORK library then you might use code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx('=',nliteral(name),nliteral(substr(name,1,length(name)-6))
  into :renames separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='HAVE'
    and upcase(name) like '%^_RATIO' escape '^'
;
quit;

proc datasets lib=work nolist;
  modify have;
    rename &amp;amp;renames;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Jan 2023 05:18:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-24T05:18:21Z</dc:date>
    <item>
      <title>How to remove suffix from variables in a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855273#M338053</link>
      <description>&lt;P&gt;I have a column where all the variables have suffixes (for example, variable name: procCode. variable options: x_ratio, y_ratio, z_ratio, a_ratio...). I want the variables to be x, y, z, a and remove the suffix '_ratio'. Is there a method where I don't have to do rename = (x_ratio=x&amp;nbsp; &amp;nbsp;y_ratio=y .....)?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 00:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855273#M338053</guid>
      <dc:creator>orchid_sugar</dc:creator>
      <dc:date>2023-01-24T00:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove suffix from variables in a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855282#M338058</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x_ratio y_ratio z_ratio a_ratio;
cards;
1 2 3 4
;

proc transpose data=have(obs=0) out=temp;
var _all_;
run;
proc sql noprint;
select catx('=',_NAME_,scan(_NAME_,1,'_')) into :rename separated by ' ' from temp;
quit;
proc datasets library=work nolist nodetails;
modify have;
rename &amp;amp;rename.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2023 05:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855282#M338058</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-24T05:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove suffix from variables in a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855285#M338060</link>
      <description>&lt;P&gt;Assuming you mean that you have a DATASET that has VARIABLES named X_RATIO, Y_RATIO etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the answer is No. If you want to rename variable you need to use a rename statement or a rename= dataset option. But that does not mean you have to TYPE them out yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get the list of variables that match your pattern and generate the OLD=NEW pairs into a macro variable. Then use the macro variable to generate the RENAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the data is named HAVE in the WORK library then you might use code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx('=',nliteral(name),nliteral(substr(name,1,length(name)-6))
  into :renames separated by ' '
  from dictionary.columns
  where libname='WORK' and memname='HAVE'
    and upcase(name) like '%^_RATIO' escape '^'
;
quit;

proc datasets lib=work nolist;
  modify have;
    rename &amp;amp;renames;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2023 05:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855285#M338060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-24T05:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove suffix from variables in a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855318#M338076</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/435788"&gt;@orchid_sugar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a column where all the variables have suffixes (for example, variable name: procCode. variable options: x_ratio, y_ratio, z_ratio, a_ratio...). I want the variables to be x, y, z, a and remove the suffix '_ratio'. Is there a method where I don't have to do rename = (x_ratio=x&amp;nbsp; &amp;nbsp;y_ratio=y .....)?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well I have to say I read the problem differently than the others. So,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/435788"&gt;@orchid_sugar&lt;/a&gt;&amp;nbsp;do you mean&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I have a column where all the &lt;FONT color="#FF0000"&gt;values&lt;/FONT&gt; have suffixes (for example, variable name: procCode. variable &lt;FONT color="#FF0000"&gt;values&lt;/FONT&gt;: x_ratio, y_ratio, z_ratio, a_ratio...). I want the &lt;FONT color="#FF0000"&gt;values&lt;/FONT&gt; to be x, y, z, a and remove the suffix '_ratio'.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you mean&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I have &lt;FONT color="#FF0000"&gt;variables&amp;nbsp;&lt;/FONT&gt;where all the &lt;FONT color="#FF0000"&gt;variable names&lt;/FONT&gt; have suffixes (for example,&lt;STRIKE&gt; variable name: procCode. variable options:&lt;/STRIKE&gt; x_ratio, y_ratio, z_ratio, a_ratio...). I want the &lt;FONT color="#FF0000"&gt;variable names&lt;/FONT&gt; to be x, y, z, a and remove the suffix '_ratio'.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 13:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855318#M338076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-24T13:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove suffix from variables in a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855454#M338092</link>
      <description>&lt;P&gt;Yes, I meant as values. I apologize for using the wrong term.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 20:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855454#M338092</guid>
      <dc:creator>orchid_sugar</dc:creator>
      <dc:date>2023-01-24T20:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove suffix from variables in a column?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855456#M338093</link>
      <description>&lt;P&gt;If the value always ends in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_ratio&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then you can remove _ratio with the following code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proccode=substr(proccode,1,length(proccode)-6);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If sometimes it ends with _ratio and sometimes it doesn't end with _ratio, or sometime _ratio is in the middle of the value (such as x_ratio_previous), then you need more programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 20:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-suffix-from-variables-in-a-column/m-p/855456#M338093</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-24T20:21:11Z</dc:date>
    </item>
  </channel>
</rss>

