<?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: Auto renaming in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21131#M3359</link>
    <description>While we usually argue against the use of macros for some things, this is a perfect (even classic) case where a macro is precisely what is needed.&lt;BR /&gt;
&lt;BR /&gt;
I'd have to do some research for the details, but that would rob you of the fun and learning.&lt;BR /&gt;
&lt;BR /&gt;
Write a macro that uses dataset information functions to determine the names of the variables in a given dataset, then your could code&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
  MERGE ALPHA(IN=IN1 KEEP=A X Y Z)&lt;BR /&gt;
               BETA (IN=IN2 KEEP=A X Y Z %rename_vars(BETA));&lt;BR /&gt;
  BY A;&lt;BR /&gt;
    IF IN1;&lt;BR /&gt;
    X_DIF=X-X_Beta;&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Just for grins and giggles, have you considered using SQL to do this for you?&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table test as&lt;BR /&gt;
  select a, x,y,z, (a.x - b.x) as x_dif, (a.y - b.y) as y_dif, (a.z - b.z) as z_dif&lt;BR /&gt;
     from ALPHA as a, BETA as b&lt;BR /&gt;
   where a.A = b.A;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
This could be macroized as well, starting with&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro diffs(ALPHA, BETA, a, x, y, z);&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table test as&lt;BR /&gt;
  select &amp;amp;a, &amp;amp;x,&amp;amp;y,&amp;amp;z, (a.&amp;amp;x - b.&amp;amp;x) as &amp;amp;x._dif, (a.&amp;amp;y - b.&amp;amp;y) as &amp;amp;y._dif, (a.&amp;amp;z - b.&amp;amp;z) as &amp;amp;z._dif&lt;BR /&gt;
     from &amp;amp;ALPHA as a, &amp;amp;BETA as b&lt;BR /&gt;
   where a&amp;amp;a = b.&amp;amp;a;&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
and it could be further generalized using the ???parm??? thingy for macros to allow for variable length parameter lists.</description>
    <pubDate>Mon, 26 May 2008 16:41:07 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-05-26T16:41:07Z</dc:date>
    <item>
      <title>Auto renaming in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21130#M3358</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I'm quite often comparing datasets with the same variable names. &lt;BR /&gt;
For this purpose I often use data steps like the following:&lt;BR /&gt;
&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
MERGE ALPHA(IN=IN1 KEEP=A X Y Z)&lt;BR /&gt;
             BETA  (IN=IN2 KEEP=A X Y Z&lt;BR /&gt;
             RENAME=(X=X_Beta Y=Y_Beta Z=Z_Beta));&lt;BR /&gt;
BY A;&lt;BR /&gt;
IF IN1;&lt;BR /&gt;
X_DIF=X-X_Beta;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
My question is whether it is possible to do renaming automatically? Giving all variables the same suffix (in this case "_Beta")? A bit in the same way as the "\autoname" option in the proc means statement?&lt;BR /&gt;
&lt;BR /&gt;
I often have to rename &amp;gt;30 variables, can it really be true that I have to make a datastep before the merge datastep?&lt;BR /&gt;
&lt;BR /&gt;
I'm very thankful for any answer.&lt;BR /&gt;
/Hans</description>
      <pubDate>Mon, 26 May 2008 14:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21130#M3358</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-05-26T14:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Auto renaming in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21131#M3359</link>
      <description>While we usually argue against the use of macros for some things, this is a perfect (even classic) case where a macro is precisely what is needed.&lt;BR /&gt;
&lt;BR /&gt;
I'd have to do some research for the details, but that would rob you of the fun and learning.&lt;BR /&gt;
&lt;BR /&gt;
Write a macro that uses dataset information functions to determine the names of the variables in a given dataset, then your could code&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
  MERGE ALPHA(IN=IN1 KEEP=A X Y Z)&lt;BR /&gt;
               BETA (IN=IN2 KEEP=A X Y Z %rename_vars(BETA));&lt;BR /&gt;
  BY A;&lt;BR /&gt;
    IF IN1;&lt;BR /&gt;
    X_DIF=X-X_Beta;&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Just for grins and giggles, have you considered using SQL to do this for you?&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table test as&lt;BR /&gt;
  select a, x,y,z, (a.x - b.x) as x_dif, (a.y - b.y) as y_dif, (a.z - b.z) as z_dif&lt;BR /&gt;
     from ALPHA as a, BETA as b&lt;BR /&gt;
   where a.A = b.A;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
This could be macroized as well, starting with&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro diffs(ALPHA, BETA, a, x, y, z);&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table test as&lt;BR /&gt;
  select &amp;amp;a, &amp;amp;x,&amp;amp;y,&amp;amp;z, (a.&amp;amp;x - b.&amp;amp;x) as &amp;amp;x._dif, (a.&amp;amp;y - b.&amp;amp;y) as &amp;amp;y._dif, (a.&amp;amp;z - b.&amp;amp;z) as &amp;amp;z._dif&lt;BR /&gt;
     from &amp;amp;ALPHA as a, &amp;amp;BETA as b&lt;BR /&gt;
   where a&amp;amp;a = b.&amp;amp;a;&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
and it could be further generalized using the ???parm??? thingy for macros to allow for variable length parameter lists.</description>
      <pubDate>Mon, 26 May 2008 16:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21131#M3359</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-05-26T16:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Auto renaming in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21132#M3360</link>
      <description>sometimes the difficulty of doing something in base SAS (without writing macros) is "no bad thing"!.&lt;BR /&gt;
Getting a $0.01 for every situation where BY-processing is the substitute for %macro iteration, would make us wealthy.&lt;BR /&gt;
Sometimes there is an alternative to data step MERGE for bringing data together.&lt;BR /&gt;
 &lt;BR /&gt;
Some situations achieve the simple effect required using  UPDATE instead of MERGE. Other situations benefit from use of MODIFY for merge/update-type processing.&lt;BR /&gt;
&lt;BR /&gt;
Comparing datasets offers another opportunity to step away from MERGE. Two alternatives come to mind: &lt;BR /&gt;
If a datastep solution is really needed, you can also use interleaving SET, but really, PROC COMPARE is shouting to be heard &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 27 May 2008 07:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-renaming-in-data-step/m-p/21132#M3360</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-05-27T07:43:38Z</dc:date>
    </item>
  </channel>
</rss>

