<?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: Rename variables with the same string suffix in different data sets to the same name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600002#M16563</link>
    <description>&lt;P&gt;No need to rename them in the original data sets. This will create the data you want and dynamically rename the variables in the Set Statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simply rename the 'WORK' to your actual library..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;   var1=1; var2=2; var3=3;   oneURN=4; run;
data two;   var1=5; var2=6; var3=7;   twoURN=8; run;
data three; var1=9; var2=1; var3=2; threeURN=3; run;

data _null_;
   set sashelp.vcolumn end=lr;
   where libname='WORK' and substr(name, length(name)-2, 3)='URN';
 
   if _n_ = 1 then call execute('data want; set ');
 
   call execute(cat(memname, '(rename=', name, '=NewVar)'));
 
   if lr then call execute(';run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var1 var2 var3 NewVar
1    2    3    4
9    1    2    3
5    6    7    8&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Oct 2019 08:24:42 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-10-29T08:24:42Z</dc:date>
    <item>
      <title>Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599981#M16557</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is I have about 400 data sets related to different cities. In each data set, there are a variable for unemployment rate and a variable for date ranging over the same period. I want to stack all 400 unemployment rate series into one panel data set (city and time). To be able to do that, the unemployment rate series need to have the same name. Right now, the variable name for UER in each small data set is like '....URN'. There's no underscore in the name. The front part contains different letters and sometime numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me to solve this problem? I really appreciate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Windy.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 06:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599981#M16557</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2019-10-29T06:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599984#M16558</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297250"&gt;@windy&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are the variables of interest all in the same position in each data set?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 06:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599984#M16558</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-29T06:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599986#M16559</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;Yeah, they are the fourth variable in every data set.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 06:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599986#M16559</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2019-10-29T06:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599994#M16560</link>
      <description>&lt;P&gt;Are all of the other variables equal named in the data sets?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 07:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599994#M16560</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-29T07:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599998#M16562</link>
      <description>&lt;P&gt;Yeah. The other variables are the same in all data sets.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 07:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/599998#M16562</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2019-10-29T07:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600002#M16563</link>
      <description>&lt;P&gt;No need to rename them in the original data sets. This will create the data you want and dynamically rename the variables in the Set Statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simply rename the 'WORK' to your actual library..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;   var1=1; var2=2; var3=3;   oneURN=4; run;
data two;   var1=5; var2=6; var3=7;   twoURN=8; run;
data three; var1=9; var2=1; var3=2; threeURN=3; run;

data _null_;
   set sashelp.vcolumn end=lr;
   where libname='WORK' and substr(name, length(name)-2, 3)='URN';
 
   if _n_ = 1 then call execute('data want; set ');
 
   call execute(cat(memname, '(rename=', name, '=NewVar)'));
 
   if lr then call execute(';run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;var1 var2 var3 NewVar
1    2    3    4
9    1    2    3
5    6    7    8&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Oct 2019 08:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600002#M16563</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-29T08:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600220#M16577</link>
      <description>&lt;P&gt;It's not working yet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the note I received. I already changed the libname to my actual library, but the same note still appears.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: There were 0 observations read from the data set SASHELP.VCOLUMN.&lt;BR /&gt;WHERE (libname='WORK') and (SUBSTR(name, (LENGTH(name)-2), 3)='URN');&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 00:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600220#M16577</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2019-10-30T00:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600225#M16578</link>
      <description>&lt;P&gt;Are the 400 data sets in the WORK library?&amp;nbsp; If not, you'll have to change the libname on the WORK statement from 'WORK' to whatever your libname is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try playing around with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=sashelp.vcolumn ;
   where libname='WORK' and substr(name, length(name)-2, 3)='URN';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should list all of the variables for data sets in the WORK library where variable name ends with 'URN' (sounds like currently it won't print anything).&amp;nbsp; Try changing the WHERE statement until it finds the variables you want.&amp;nbsp; Then you can use that WHERE statement in the DATA _NULL_ step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 01:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600225#M16578</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-10-30T01:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables with the same string suffix in different data sets to the same name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600232#M16579</link>
      <description>&lt;P&gt;Oh yeah. It's working now.&lt;/P&gt;&lt;P&gt;But I need to move all of data sets to the work library because this code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if _n_ = 1 then call execute('data want; set ');&lt;/P&gt;&lt;P&gt;execute the data sets in the work library. I was trying to change to the actual library, but the code didn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, thank you so much for your help&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;. Really appreciate that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 02:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-with-the-same-string-suffix-in-different-data/m-p/600232#M16579</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2019-10-30T02:01:18Z</dc:date>
    </item>
  </channel>
</rss>

