<?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: Macro replaceprefix: how to modify to pull labels and formats? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191174#M36064</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had tried that, but now see the error was that I didn't remove the "drop &amp;amp;&amp;amp;dsvn&amp;amp;i;" line. Thanks so much!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Feb 2014 22:32:42 GMT</pubDate>
    <dc:creator>blackpebble</dc:creator>
    <dc:date>2014-02-28T22:32:42Z</dc:date>
    <item>
      <title>Macro replaceprefix: how to modify to pull labels and formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191172#M36062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have monthly data collected over two years. The datafiles have M# at the start of some of the variables, but not all of them (some have a different prefix, some have no prefix). I have successfully used the macro in this paper (&lt;A href="http://support.sas.com/resources/papers/proceedings09/075-2009.pdf" title="http://support.sas.com/resources/papers/proceedings09/075-2009.pdf"&gt;http://support.sas.com/resources/papers/proceedings09/075-2009.pdf&lt;/A&gt;) to strip off the prefix using repeated runs of the macro to capture all of the variables that I need to have the prefix removed from. The problem is that this creates new variables that do not have the labels and formats that were assigned to the original variables. How can I modify this code to pull over the labels and formats as well?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code from Weng and Fung paper:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%macro replaceprefix(dsn,dsnout,start,end,oldprefix,newprefix); &lt;/P&gt;&lt;P&gt;data temp; &lt;/P&gt;&lt;P&gt;set &amp;amp;dsn.; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;%LET ds=%SYSFUNC(OPEN(temp,i)); &lt;/P&gt;&lt;P&gt;%let ol=%length(&amp;amp;oldprefix.); &lt;/P&gt;&lt;P&gt;%do i=&amp;amp;start %to &amp;amp;end; &lt;/P&gt;&lt;P&gt;%let dsvn&amp;amp;i=%SYSFUNC(VARNAME(&amp;amp;ds,&amp;amp;i)); &lt;/P&gt;&lt;P&gt;%let l=%length(&amp;amp;&amp;amp;dsvn&amp;amp;i); &lt;/P&gt;&lt;P&gt;%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)); &lt;/P&gt;&lt;P&gt;%end; &lt;/P&gt;&lt;P&gt;data &amp;amp;dsnout.; &lt;/P&gt;&lt;P&gt;set temp; &lt;/P&gt;&lt;P&gt;%do i=&amp;amp;start %to &amp;amp;end; &lt;/P&gt;&lt;P&gt;&amp;amp;&amp;amp;vn&amp;amp;i=&amp;amp;&amp;amp;dsvn&amp;amp;i; &lt;/P&gt;&lt;P&gt;drop &amp;amp;&amp;amp;dsvn&amp;amp;i; &lt;/P&gt;&lt;P&gt;%end; &lt;/P&gt;&lt;P&gt;%let rc=%SYSFUNC(CLOSE(&amp;amp;ds)); &lt;/P&gt;&lt;P&gt;proc contents data=&amp;amp;dsnout. varnum; &lt;/P&gt;&lt;P&gt;title 'Replacing Prefix on Selected variables '; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;%mend replaceprefix; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Feb 2014 22:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191172#M36062</guid>
      <dc:creator>blackpebble</dc:creator>
      <dc:date>2014-02-28T22:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Macro replaceprefix: how to modify to pull labels and formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191173#M36063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not just rename the variables rather than copy/drop?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data &amp;amp;dsnout.; &lt;/P&gt;&lt;P&gt;set temp; &lt;/P&gt;&lt;P&gt;%do i=&amp;amp;start %to &amp;amp;end; &lt;/P&gt;&lt;P&gt;rename &amp;amp;&amp;amp;dsvn&amp;amp;i=&amp;amp;&amp;amp;vn&amp;amp;i; &lt;/P&gt;&lt;P&gt;%end; &lt;/P&gt;&lt;P&gt;%let rc.....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Feb 2014 22:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191173#M36063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-02-28T22:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro replaceprefix: how to modify to pull labels and formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191174#M36064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had tried that, but now see the error was that I didn't remove the "drop &amp;amp;&amp;amp;dsvn&amp;amp;i;" line. Thanks so much!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Feb 2014 22:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191174#M36064</guid>
      <dc:creator>blackpebble</dc:creator>
      <dc:date>2014-02-28T22:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro replaceprefix: how to modify to pull labels and formats?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191175#M36065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The paper is describing a solution for a problem that is not yours.&amp;nbsp; As you understand the solution for the problem you can modify that.&lt;/P&gt;&lt;P&gt;Perhaps more easy to build your own. My analyses: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 1: Collect the needed information on variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; The paper is using Proc SQL on the dictionary&amp;nbsp; -- macro rename&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Collecting the list in macro-array.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;Step 2: Execute changes &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; The paper is using proc datasets ... modify&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; As the the list is a macro array the list is processed in macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0ahh0eqtadmp3n1uwv55i2gyxiz.htm" title="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n0ahh0eqtadmp3n1uwv55i2gyxiz.htm"&gt;Base SAS(R) 9.3 Procedures Guide, Second Edition&lt;/A&gt;&amp;nbsp; Proc datasets modify... &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; You can use attrib to assing all attributes as well at the same maco process statements&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Needing some additional logic can be don with macro programming %if ... %then&amp;nbsp; handling the strings&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Feb 2014 22:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-replaceprefix-how-to-modify-to-pull-labels-and-formats/m-p/191175#M36065</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-02-28T22:38:16Z</dc:date>
    </item>
  </channel>
</rss>

