<?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 Retain original format and label after renaming variables in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327921#M9577</link>
    <description>&lt;P&gt;Hi there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the macro %macro replaceprefix(lib,dsn,start,end,oldprefix,newprefix); to perform the prefix addition on&amp;nbsp;selected variables and it is accesible from &lt;A href="http://support.sas.com/resources/papers/proceedings09/075-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/075-2009.pdf&lt;/A&gt;. However, it doesn't retain the format and label of the variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I please ask your help to shed some lights on this? Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2017 04:16:08 GMT</pubDate>
    <dc:creator>Miracle</dc:creator>
    <dc:date>2017-01-27T04:16:08Z</dc:date>
    <item>
      <title>Retain original format and label after renaming variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327921#M9577</link>
      <description>&lt;P&gt;Hi there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the macro %macro replaceprefix(lib,dsn,start,end,oldprefix,newprefix); to perform the prefix addition on&amp;nbsp;selected variables and it is accesible from &lt;A href="http://support.sas.com/resources/papers/proceedings09/075-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/075-2009.pdf&lt;/A&gt;. However, it doesn't retain the format and label of the variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I please ask your help to shed some lights on this? Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 04:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327921#M9577</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2017-01-27T04:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Retain original format and label after renaming variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327943#M9578</link>
      <description>&lt;P&gt;Hi Wong,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why don't you set the format and label once more after the renaming.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the&amp;nbsp;&lt;SPAN&gt; %macro replaceprefix(lib,dsn,start,end,oldprefix,newprefi&lt;/SPAN&gt;&lt;SPAN&gt;x); try adding the following.&lt;/SPAN&gt;&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; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA    &amp;lt;lib&amp;gt;.&amp;lt;datasetname&amp;gt;;
    SET &amp;lt;lib&amp;gt;.&amp;lt;datasetname&amp;gt;;
        FORMAT &amp;lt;variable name&amp;gt; &amp;lt;format&amp;gt;;
	INFORMAT  &amp;lt;variable name&amp;gt; &amp;lt;format&amp;gt;;
        LABEL &amp;lt;label u want to give&amp;gt;;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 07:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327943#M9578</guid>
      <dc:creator>ankit___gupta</dc:creator>
      <dc:date>2017-01-27T07:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Retain original format and label after renaming variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327998#M9588</link>
      <description>&lt;P&gt;Shed some light? &amp;nbsp;Yes. &amp;nbsp;Fix? &amp;nbsp;No.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll have to inspect the details within the macro you referenced. &amp;nbsp;It uses a DATA step to copy the original variables to new variables (then subsequently drops the original variables). &amp;nbsp;When you do that, formats and labels do not get copied, just the data values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are other macros within the paper that don't do that, using PROC DATASETS instead of a DATA step. &amp;nbsp;But those macros don't perform the exact same function as the one you are using.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 12:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/327998#M9588</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-27T12:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Retain original format and label after renaming variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/328056#M9592</link>
      <description>&lt;P&gt;Problem's now solved after adding a few lines of SAS statements to the macro.&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 16:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/328056#M9592</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2017-01-27T16:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Retain original format and label after renaming variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/328182#M9594</link>
      <description>&lt;P&gt;Hi wong ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what was the solution ? Can u share ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jan 2017 02:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/328182#M9594</guid>
      <dc:creator>ankit___gupta</dc:creator>
      <dc:date>2017-01-28T02:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Retain original format and label after renaming variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/328212#M9596</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82369"&gt;@ankit___gupta&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Please find modified SAS code below (last 2 %let statements within the first do loop, label and format statement in the second datastep).&lt;/P&gt;&lt;P&gt;HTH. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Paper 075-2009
Renaming in Batches
Vincent Weng, Educational Testing Service, Princeton, NJ
Ying Feng, CTB/McGraw-Hill, Monterey, CA 

accessible via http://support.sas.com/resources/papers/proceedings09/075-2009.pdf
*/

/* Replacing Prefix on Selected Variables */
%macro replaceprefix(lib,dsn,start,end,oldprefix,newprefix);
proc contents data=&amp;amp;lib..&amp;amp;dsn.; title 'before renaming'; run;
data temp; set &amp;amp;lib..&amp;amp;dsn.; run;
%LET ds=%SYSFUNC(OPEN(temp,i));
%LET ol=%LENGTH(&amp;amp;oldprefix.);
%DO i=&amp;amp;start %TO &amp;amp;end;
	%LET dsvn&amp;amp;i=%SYSFUNC(VARNAME(&amp;amp;ds,&amp;amp;i));
	%LET l=%LENGTH(&amp;amp;&amp;amp;dsvn&amp;amp;i);
	%LET vn&amp;amp;i=&amp;amp;newprefix.%SUBSTR(&amp;amp;&amp;amp;dsvn&amp;amp;i,&amp;amp;ol+1,%EVAL(&amp;amp;l-&amp;amp;ol));

	%LET dsvnlab&amp;amp;i=%BQUOTE(%SYSFUNC(VARLABEL(&amp;amp;ds,%SYSFUNC(varnum(&amp;amp;ds,&amp;amp;&amp;amp;dsvn&amp;amp;i)))));
	%LET dsvnfmt&amp;amp;i=%SYSFUNC(VARFMT(&amp;amp;ds,%SYSFUNC(varnum(&amp;amp;ds,&amp;amp;&amp;amp;dsvn&amp;amp;i))));

%end;
data &amp;amp;lib..&amp;amp;dsn.;
	set temp;

	%DO i=&amp;amp;start %TO &amp;amp;end; 
		&amp;amp;&amp;amp;vn&amp;amp;i=&amp;amp;&amp;amp;dsvn&amp;amp;i; 
		label &amp;amp;&amp;amp;vn&amp;amp;i=%STR(&amp;amp;&amp;amp;dsvnlab&amp;amp;i);
		format &amp;amp;&amp;amp;vn&amp;amp;i &amp;amp;&amp;amp;dsvnfmt&amp;amp;i.;
		drop &amp;amp;&amp;amp;dsvn&amp;amp;i; 
	%end;
	%let rc=%SYSFUNC(CLOSE(&amp;amp;ds));
	proc contents data=&amp;amp;lib..&amp;amp;dsn.;
	title 'Replacing Prefix on Selected variables ';
run;
%mend replaceprefix;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Jan 2017 13:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Retain-original-format-and-label-after-renaming-variables/m-p/328212#M9596</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2017-01-28T13:58:39Z</dc:date>
    </item>
  </channel>
</rss>

