<?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: Add wanted Label value column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672289#M202027</link>
    <description>&lt;P&gt;Thank you for your response.&lt;/P&gt;
&lt;P&gt;As you can see the data structure is long and not wide!&lt;/P&gt;
&lt;P&gt;My questions was how to create a new column that will contain wanted labels&amp;nbsp; names.&lt;/P&gt;
&lt;P&gt;As you can see in my post I created the new column with manual typing the label and my question was how to do it in a better way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 Jul 2020 10:18:55 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-07-25T10:18:55Z</dc:date>
    <item>
      <title>Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672278#M202019</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a wide structure summary table.&lt;/P&gt;
&lt;P&gt;In this table for each Business ID there are 9 columns with 3 groups of variables:&lt;/P&gt;
&lt;P&gt;a-amount of Income in each period (YYMM).Fields: amount2001&amp;nbsp;amount2004&amp;nbsp;amount2005&lt;/P&gt;
&lt;P&gt;b-Number of bank transactions in each period (YYMM).Fields: NrTrans2001,NrTrans2004,NrTrans2005&lt;/P&gt;
&lt;P&gt;c-Number of customers in each period (YYMM) .Fields: NrCustomers2001,NrCustomers2004,NrCustomers2005&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to add a new column to this wide summary table with name of wanted label.(name of field :Wanted_label&lt;/P&gt;
&lt;P&gt;The new column values will be as following:&lt;/P&gt;
&lt;P&gt;For amount fields the label will be : Income YYMM&lt;/P&gt;
&lt;P&gt;For NrTrans fields the label will be : Number Transactions YYMM&lt;/P&gt;
&lt;P&gt;For NrCustomers fields the label will be : Number Customers YYMM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the clever way to do it please ?&lt;/P&gt;
&lt;P&gt;In real world I have many fields and I think that it is not clever way to type for each of them the label value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data LongSummaryTbl;
Input BusinessID Field $ value;
cards;
1 amount2001 10
1 amount2004 12
1 amount2005 14
1 NrTrans2001 16
1 NrTrans2004 18
1 NrTrans2005 13
1 NrCustomers2001 8
1 NrCustomers2004 4
1 NrCustomers2005 7
;
Run;


Data&amp;nbsp;LongSummaryTbl2;
set&amp;nbsp;LongSummaryTbl;

IF&amp;nbsp;field='amount2001'&amp;nbsp;then&amp;nbsp;Wanted_label='Income 2001';
IF&amp;nbsp;field='amount2004'&amp;nbsp;then&amp;nbsp;Wanted_label='Income 2004';
IF&amp;nbsp;field='amount2005'&amp;nbsp;then&amp;nbsp;Wanted_label='Income 2005';

IF&amp;nbsp;field='NrTrans2001'&amp;nbsp;then&amp;nbsp;Wanted_label=' Number Transactions 2001';
IF&amp;nbsp;field='NrTrans2004'&amp;nbsp;then&amp;nbsp;Wanted_label=' Number Transactions 2004';
IF&amp;nbsp;field='NrTrans2005'&amp;nbsp;then&amp;nbsp;Wanted_label=' Number Transactions 2005';

IF&amp;nbsp;field='NrCustomers2001'&amp;nbsp;then&amp;nbsp;Wanted_label=' Number Customers 2001';
IF&amp;nbsp;field='NrCustomers2004'&amp;nbsp;then&amp;nbsp;Wanted_label=' Number Customers 2004';
IF&amp;nbsp;field='NrCustomers2005'&amp;nbsp;then&amp;nbsp;Wanted_label=' Number Customers 2005';

Run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 17:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672278#M202019</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-25T17:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672281#M202022</link>
      <description>&lt;P&gt;Please format your code.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 09:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672281#M202022</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-25T09:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672284#M202025</link>
      <description>&lt;P&gt;What do you mean please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 09:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672284#M202025</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-25T09:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672288#M202026</link>
      <description>&lt;P&gt;The clever thing to do has been posted on this board many times, by a number of people.&amp;nbsp; I'm not sure if it has ever been posted in answer to one of your questions, so now is the time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The clever thing to do is to store your data in long format instead of wide format.&amp;nbsp; You have come up with one more reason why this is wise.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 10:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672288#M202026</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-07-25T10:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672289#M202027</link>
      <description>&lt;P&gt;Thank you for your response.&lt;/P&gt;
&lt;P&gt;As you can see the data structure is long and not wide!&lt;/P&gt;
&lt;P&gt;My questions was how to create a new column that will contain wanted labels&amp;nbsp; names.&lt;/P&gt;
&lt;P&gt;As you can see in my post I created the new column with manual typing the label and my question was how to do it in a better way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 10:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672289#M202027</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-25T10:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672290#M202028</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What do you mean please?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your code is very difficult to read, and needs to be formatted properly so we can read it.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 10:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672290#M202028</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-25T10:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672291#M202029</link>
      <description>&lt;P&gt;I think that this code will solve the problem but I haven't checked it because I don't have SAS in my personal PC.&lt;/P&gt;
&lt;P&gt;What do you think?Will it work well?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Long2;&lt;BR /&gt;Set Long;&lt;BR /&gt;YYMM=SUBSTR(field,LENGTH(TRIM(Field))-4);							
If Substr(Field,1,6)="amount" then wantedlabel=catx(' ','Income',yymm);							
If Substr(Field,1,7)="NrTrans" then wantedlabel=catx(' ','Number Transactions ',yymm);							
If Substr(Field,1,11)="NrCustomers " then wantedlabel=catx(' ','Number Customers ',yymm);	&lt;BR /&gt;Run;&lt;BR /&gt;						
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Jul 2020 10:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672291#M202029</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-25T10:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672292#M202030</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Data Long2;Set Long;YYMM=SUBSTR(field,LENGTH(TRIM(Field))-4);		&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find three commands on one line to be difficult to read, and contrary to what almost everyone else does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, what are you trying to do here? If you need YYMM in a separate column, that makes sense to me and is easy to do, but why would you need to change "amount" to "income", etc. and then append YYMM?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;yymm=scan(field,-1,'_');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 10:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672292#M202030</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-25T10:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672301#M202039</link>
      <description>&lt;P&gt;&amp;gt;&amp;nbsp;&lt;SPAN&gt;What do you mean please?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Just look You second data step is all on one line.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 12:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672301#M202039</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-25T12:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672337#M202045</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What do you mean please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you edit the code in a code box without re-opening the code box then the line breaks can get messed up.&amp;nbsp; Normally just opening the Insert SAS Code box and closing it will fix the issue.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 17:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672337#M202045</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-25T17:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672340#M202047</link>
      <description>&lt;P&gt;Looks like you just want to use TRANWRD() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data LongSummaryTbl2;
  set LongSummaryTbl;
  length Wanted_Label $50 ;
  wanted_label = field;
  wanted_label = tranwrd(wanted_label ,'amount','Income ');
  wanted_label = tranwrd(wanted_label ,'NrTrans',' Number Transactions ');
  wanted_label = tranwrd(wanted_label ,'NrCustomers',' Number Customers ');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Jul 2020 17:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672340#M202047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-25T17:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672343#M202048</link>
      <description>&lt;P&gt;This is a problem with this web site!!!&lt;/P&gt;
&lt;P&gt;I write it in multiple rows and It appears in one line!&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 19:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672343#M202048</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-25T19:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add wanted Label value column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672373#M202064</link>
      <description>&lt;P&gt;Yes this website can corrupt formatting when you alter lines after pasting.&lt;/P&gt;
&lt;P&gt;It is up to you to ensure that your post is legible.&lt;/P&gt;
&lt;P&gt;Delete and paste again.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 05:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-wanted-Label-value-column/m-p/672373#M202064</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-07-26T05:59:11Z</dc:date>
    </item>
  </channel>
</rss>

