<?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 numeric decimal to month label in datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734847#M228915</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp; Below some options how you could go about this.&lt;/P&gt;
&lt;P&gt;Given that you generate the monyy names based on when you execute the code, I assume that you might want to run the code at different dates/months and though the names would change. If this is the case then may-be better only change the variable label and not the variable name as this will allow you to use a constant set of variable names in your code (else you would always have to change all the names throughout your code).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let mth4=%sysfunc(intnx(month, %sysfunc(today()),-4), monyy5.);
%let mth3=%sysfunc(intnx(month, %sysfunc(today()),-3), monyy5.);
%put &amp;amp;mth4 &amp;amp;mth3;

/* option 1 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

data want1;
  set have;
  rename trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;
run;

/* option 2 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

data want2;
  set have;
  label trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;
run;

/* option 3 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

proc datasets lib=work nolist;
  modify have;
    rename trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4
    ;
  run;
quit;

/* option 4 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

proc datasets lib=work nolist;
  modify have;
    label trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4
    ;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Apr 2021 03:02:58 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-04-17T03:02:58Z</dc:date>
    <item>
      <title>Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734835#M228910</link>
      <description>&lt;TABLE width="451"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="451"&gt;%let mth4=%sysfunc(intnx(month, %sysfunc(today()),-4), monyy5.);&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;%let mth3=%sysfunc(intnx(month, %sysfunc(today()),-3), monyy5.);&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;%put &amp;nbsp; &amp;amp;mth4 &amp;amp;mth3;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;data have;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;trans_4 = 0.9983;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;trans_3 = 0.8988;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;run;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;I want to assign the corresponding date to trans based on the month number&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;So trans_4 should show as Dec20 and trans3 as Jan21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1. Would I need to convert to a character to do this?&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2. What would be the way to replace the name&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;I tried this and receive error&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;data have;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;trans_4 = 0.9983;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;trans_3 = 0.8988;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;trans_4 = "&amp;amp;mth4."d;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;SYMBOLGEN: Macro variable MTH4 resolves to DEC20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;NOTE: Line generated by the macro variable "MTH4".&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; mth4=&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(intnx(month, &lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(today()),-4), monyy5.); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; mth3=&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(intnx(month, &lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(today()),-3), monyy5.); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; &amp;amp;mth4 &amp;amp;mth3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;trans_4 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0.9983&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;trans_3 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0.8988&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;trans_4 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;"&amp;amp;mth4."d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 00:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734835#M228910</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-04-17T00:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734841#M228911</link>
      <description>&lt;P&gt;Try this. You need to supply a complete date string in the form of 01Jan2021:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mth4=%sysfunc(intnx(month, %sysfunc(today()),-4), date9.);

%let mth3=%sysfunc(intnx(month, %sysfunc(today()),-3), date9.);

%put &amp;amp;mth4 &amp;amp;mth3;

data have;

trans_4 = 0.9983;

trans_3 = 0.8988;

trans_4 = "&amp;amp;mth4."d;
format trans_4 date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Apr 2021 01:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734841#M228911</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-17T01:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734844#M228912</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;So trans_4 should &lt;STRONG&gt;show&lt;/STRONG&gt; as Dec20 and trans3 as Jan21&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;What should "show" as mmmyy?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;1. The variable name/header when you print the data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2. The data itself when you print it? If so then what's the logic for&amp;nbsp;&lt;SPAN&gt;0.9983 to show as Dec20?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;3. Or do you really want to replace the values stored in the variables with a SAS date value (which you then format so it prints as desired)?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're after 2. or 3. and assuming you've got more than the two source values to start with, please explain us the logic required how to "replace" your source values with mmmYY.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 02:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734844#M228912</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-17T02:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734845#M228913</link>
      <description>When I do this trans_4 = "&amp;amp;mth4."d;&lt;BR /&gt;the value becomes the date.  I want to keep the decimal date value and rename tran_4 wth the date name.  So tran_4 should have the header name of DEC20 and keep the decimal value in the variable.  Is that possible</description>
      <pubDate>Sat, 17 Apr 2021 02:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734845#M228913</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-04-17T02:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734846#M228914</link>
      <description>&lt;P&gt;It is not at all clear what you are trying to do.&amp;nbsp; You have shown the input dataset.&amp;nbsp; Show what you want the output dataset to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know what SAS code you want to generate show that code, we can then help you generate the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also can you explain why you think this transformation will help you in some way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to RENAME as your subject line says then use the RENAME statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  rename trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Apr 2021 02:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734846#M228914</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-17T02:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734847#M228915</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp; Below some options how you could go about this.&lt;/P&gt;
&lt;P&gt;Given that you generate the monyy names based on when you execute the code, I assume that you might want to run the code at different dates/months and though the names would change. If this is the case then may-be better only change the variable label and not the variable name as this will allow you to use a constant set of variable names in your code (else you would always have to change all the names throughout your code).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let mth4=%sysfunc(intnx(month, %sysfunc(today()),-4), monyy5.);
%let mth3=%sysfunc(intnx(month, %sysfunc(today()),-3), monyy5.);
%put &amp;amp;mth4 &amp;amp;mth3;

/* option 1 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

data want1;
  set have;
  rename trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;
run;

/* option 2 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

data want2;
  set have;
  label trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;
run;

/* option 3 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

proc datasets lib=work nolist;
  modify have;
    rename trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4
    ;
  run;
quit;

/* option 4 */
data have;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
run;

proc datasets lib=work nolist;
  modify have;
    label trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4
    ;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 03:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734847#M228915</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-17T03:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734876#M228930</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;Thanks your solution worked.&amp;nbsp; One more issue.&amp;nbsp; If you look at the code here I want to format trans_4 and trans_3 in decimal format.&amp;nbsp; However I need to flip or pivot the data so that Count retains its numeric value and trans_4_&amp;amp;mth4 and trans_3_&amp;amp;mth3 are in decimal format Percent8.2&amp;nbsp;&amp;nbsp; This works in the datastep however I loose the desired decimal format during proc transpose.&amp;nbsp; Is there a way to retain the desired decimal format even after the proc transpose???&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; Category=&lt;/FONT&gt;&lt;FONT face="Courier New" color="#800080"&gt;'MyCategory'&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; count = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;7000&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; trans_4 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0.9983&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; trans_3 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0.8988&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; trans_4 trans_3 &lt;/FONT&gt;&lt;FONT face="Courier New" color="#008080"&gt;percent8.2&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; want1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;rename&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;transpose&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" color="#0000ff"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=want1 &lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=want2 &lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;let&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; count &amp;amp;mth4 &amp;amp;mth3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Category;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 14:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734876#M228930</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-04-17T14:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Rename numeric decimal to month label in datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734998#M228957</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;Going forward please ask "unrelated" follow-up questions as a new question with a matching subject line. Not only will this make this forum more useful for people searching answers to questions already asked and resolved, it will also give your new question more attention as many people answering questions won't look into threads already marked as resolved.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always specifically call out someone in your new question if you want them to become aware of your new question using "@&amp;lt;name&amp;gt;". This will create a notification for the mentioned user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now to your question:&lt;/P&gt;
&lt;P&gt;If you've got only numerical variables to transpose then the resulting transposed column will be numerical.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1618708302484.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58235i4E2FE499188DB1FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1618708302484.png" alt="Patrick_1-1618708302484.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;SAS formats apply on columns (variables) and not on cells. Because the variables you transpose have different formats SAS has to use a default format on the transposed column (I believe that's best32.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the docu for the Var statement of Proc Transpose&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p19h5tsoknssr4n18gbl9xle0kq1.htm" target="_self"&gt;here&lt;/A&gt; you can find:&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_3-1618708653529.png" style="width: 831px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58237i9B10FCD80DB8670E/image-dimensions/831x113?v=v2" width="831" height="113" role="button" title="Patrick_3-1618708653529.png" alt="Patrick_3-1618708653529.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To have different formatting per cell you need to convert the numerical values to strings. And for Proc Transpose to do so one of the variables must be of type character. For conversion numeric to character Proc Transpose will use the format assigned to the variable (or the default of best32. if there is no explicit format defined).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below two options how you can get what you're after. Please note that if using the first option there can be leading blanks in the transposed values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mth4=%sysfunc(intnx(month, %sysfunc(today()),-4), monyy5.);
%let mth3=%sysfunc(intnx(month, %sysfunc(today()),-3), monyy5.);
%put &amp;amp;mth4 &amp;amp;mth3;

data have;
  Category='MyCategory';
  count = 7000;
  trans_4 = 0.9983;
  trans_3 = 0.8988;
  format trans_4 trans_3 percent8.2;
run;

/** option 1 **/
data want1;
  set have;
  length _dummy $1;
  call missing(_dummy);
  rename trans_3=&amp;amp;mth3 trans_4=&amp;amp;mth4;
run;

/* add _dummy to var statement to "force" proc transpose to create a character variable */
/* for the transposed values. Drop _dummy from output as not wanted there               */
proc transpose 
    data=want1 
    out=want2(where=(upcase(_name_) ne '_DUMMY'))
    let;
  /* if desired explicit format statements allows to overwrite formats from source */
  format count comma.;
  var _dummy count &amp;amp;mth4 &amp;amp;mth3;
  by Category;
run;


/** option 2 **/
/* -l option in put statement to left align result */
data want1; 
  set have;
  count_c = put(7000,best32. -l);
  &amp;amp;mth3=put(trans_3,percent8.2 -l);
  &amp;amp;mth4=put(trans_4,percent8.2 -l);
run;

proc transpose 
    data=want1 
    out=want2
    let;
  var count_c &amp;amp;mth4 &amp;amp;mth3;
  by Category;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Apr 2021 01:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-numeric-decimal-to-month-label-in-datastep/m-p/734998#M228957</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-18T01:39:11Z</dc:date>
    </item>
  </channel>
</rss>

