<?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 and rename variables if there's a certain string in the variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/777121#M247191</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404436"&gt;@tutu_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset like this, the dataset name is data1&lt;/P&gt;
&lt;P&gt;PIN&amp;nbsp; &amp;nbsp; &amp;nbsp; data1_S00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data1_ZC00&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to rename the variable if the variable name contains "S00" or "S96" or "S97"&lt;/P&gt;
&lt;P&gt;Here is the code I wrote, it does the job but it does a lot of unnecessary computation.&lt;/P&gt;
&lt;P&gt;The warning is like this "ERROR: Variable s805_S96 is not on file WORK.WANT", This variable is not even in the dataset, I don't know how to get rid of the warning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro rename(data1);&lt;/P&gt;
&lt;P&gt;data want_new; set want;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint ;&lt;BR /&gt;select cats(name,'=&amp;amp;data1') into :renames1 separated by ' '&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname='WORK' and memname='WANT_NEW' and upcase(name) like '%_S00%' or upcase(name) like '%_S96%';&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc datasets nolist library=work;&lt;BR /&gt;modify want_new;&lt;BR /&gt;rename &amp;amp;renames1;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%rename(data1);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suggest that you create a data set from your first sql so you can see the name(s) selected and what that string&lt;/P&gt;
&lt;P&gt;"&amp;nbsp; name,'=&amp;amp;data1' " actually looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider looking into CALL EXECUTE with the data generated by the sql to have nicer tools to write lines of code instead of hoping that the macros you create, especially if there multiples that match your search requirement.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Oct 2021 20:53:47 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-28T20:53:47Z</dc:date>
    <item>
      <title>How to select and rename variables if there's a certain string in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/777120#M247190</link>
      <description>&lt;P&gt;I have a dataset like this, the dataset name is data1&lt;/P&gt;&lt;P&gt;PIN&amp;nbsp; &amp;nbsp; &amp;nbsp; data1_S00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data1_ZC00&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to rename the variable if the variable name contains "S00" or "S96" or "S97"&lt;/P&gt;&lt;P&gt;Here is the code I wrote, it does the job but it does a lot of unnecessary computation.&lt;/P&gt;&lt;P&gt;The warning is like this "ERROR: Variable s805_S96 is not on file WORK.WANT", This variable is not even in the dataset, I don't know how to get rid of the warning.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro rename(data1);&lt;/P&gt;&lt;P&gt;data want_new; set want;run;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;BR /&gt;select cats(name,'=&amp;amp;data1') into :renames1 separated by ' '&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname='WORK' and memname='WANT_NEW' and upcase(name) like '%_S00%' or upcase(name) like '%_S96%';&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets nolist library=work;&lt;BR /&gt;modify want_new;&lt;BR /&gt;rename &amp;amp;renames1;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%rename(data1);&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 20:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/777120#M247190</guid>
      <dc:creator>tutu_</dc:creator>
      <dc:date>2021-10-28T20:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to select and rename variables if there's a certain string in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/777121#M247191</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404436"&gt;@tutu_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset like this, the dataset name is data1&lt;/P&gt;
&lt;P&gt;PIN&amp;nbsp; &amp;nbsp; &amp;nbsp; data1_S00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data1_ZC00&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xxx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to rename the variable if the variable name contains "S00" or "S96" or "S97"&lt;/P&gt;
&lt;P&gt;Here is the code I wrote, it does the job but it does a lot of unnecessary computation.&lt;/P&gt;
&lt;P&gt;The warning is like this "ERROR: Variable s805_S96 is not on file WORK.WANT", This variable is not even in the dataset, I don't know how to get rid of the warning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro rename(data1);&lt;/P&gt;
&lt;P&gt;data want_new; set want;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint ;&lt;BR /&gt;select cats(name,'=&amp;amp;data1') into :renames1 separated by ' '&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname='WORK' and memname='WANT_NEW' and upcase(name) like '%_S00%' or upcase(name) like '%_S96%';&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc datasets nolist library=work;&lt;BR /&gt;modify want_new;&lt;BR /&gt;rename &amp;amp;renames1;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%rename(data1);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suggest that you create a data set from your first sql so you can see the name(s) selected and what that string&lt;/P&gt;
&lt;P&gt;"&amp;nbsp; name,'=&amp;amp;data1' " actually looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider looking into CALL EXECUTE with the data generated by the sql to have nicer tools to write lines of code instead of hoping that the macros you create, especially if there multiples that match your search requirement.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 20:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/777121#M247191</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-28T20:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to select and rename variables if there's a certain string in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/789857#M252811</link>
      <description>Thank you!</description>
      <pubDate>Wed, 12 Jan 2022 23:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-and-rename-variables-if-there-s-a-certain-string/m-p/789857#M252811</guid>
      <dc:creator>tutu_</dc:creator>
      <dc:date>2022-01-12T23:12:50Z</dc:date>
    </item>
  </channel>
</rss>

