<?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: Use header name in the rows in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586642#M14539</link>
    <description>Good to know, If you are satisfied with the solution and if it actually worked could you mark this solution as accepted so it will help other sas community users.</description>
    <pubDate>Fri, 06 Sep 2019 07:10:54 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2019-09-06T07:10:54Z</dc:date>
    <item>
      <title>Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586340#M14461</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have three columns T1,T2,T3 where T1 contains names, T2 contains Age and T3 contains Gender. Now, I want to add a new columns, lets say T_ONE which will have concatenation of header T1 with name (for instance, T1 - John, T1 - Brad and so on), T_TWO which will have concatenation of header T2 with age (for instance T2 -- 25, T2 - 35 etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In another words, I just want to use my header name in the observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 09:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586340#M14461</guid>
      <dc:creator>hs71</dc:creator>
      <dc:date>2019-09-05T09:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586342#M14462</link>
      <description>&lt;P&gt;Hi and welcome to the SAS Communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this is what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input T1 $ T2 T3 $;
datalines;
Alice 10 Female
Tim   30 Male  
Bob   50 Male  
;

data want;
    set have;
    t_one=catx(' - ', vname(T1), T1);
    t_two=catx(' - ', vname(T2), T2);
    t_three=catx(' - ', vname(T3), T3);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2019 09:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586342#M14462</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-05T09:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586345#M14463</link>
      <description>&lt;P&gt;Thanks a lot. The output is exactly what I want. But is there another way as well where I do not have to define the column name explicitly?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 09:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586345#M14463</guid>
      <dc:creator>hs71</dc:creator>
      <dc:date>2019-09-05T09:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586346#M14464</link>
      <description>&lt;P&gt;Why don't you want to reference the variables explicitly? Do you have a lot of them?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 09:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586346#M14464</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-05T09:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586348#M14465</link>
      <description>&lt;P&gt;Yes, I have quite a few in my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was having an idea...but dont know how to execute? Can we address the sas to use the header of second column and concatenate it with the name, then third column and so on. Because the sequence of columns in my dataset is constant. Always first column will be T1, second will be T2 and so on.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 09:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586348#M14465</guid>
      <dc:creator>hs71</dc:creator>
      <dc:date>2019-09-05T09:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586375#M14470</link>
      <description>&lt;P&gt;I believe one way is to simply the approach by using the arrays as below, the below code i used with work for character variables, the same need to be repeated for numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input T1 $ T2 T3 $;
datalines;
Alice 10 Female
Tim   30 Male  
Bob   50 Male  
;

data want;
    set have;
    array var1(*) t1 t3;
     array var3(*) $100. T_1 T_3;
     do i = 1 to dim(var3);
     if vtype(var1(i))='C' then var3(i)=catx(' - ', vname(var1(i)), var1(i));
          *if vtype(var2(i))='N' then var3(i)=catx(' - ', vname(var2(i)), var2(i));
          end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2019 11:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586375#M14470</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-05T11:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586400#M14472</link>
      <description>&lt;P&gt;Here is a dynamic approach by which we can derive n number of variables as you expected&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input T1 $ T2 T3 $;
datalines;
Alice 10 Female
Tim   30 Male  
Bob   50 Male  
;

proc sql noprint;
/*create macro variables for character and numeric variables*/
 select name into: chars separated by ' ' from dictionary.columns where libname='WORK' and memname='HAVE' and type='char' order by type, name;
  select name into: nums separated by ' ' from dictionary.columns where libname='WORK' and memname='HAVE' and type='num' order by type, name;
  /*create macro variables for character and numeric variables with names changed i.e to have names like T_1... instead of T1*/
select prxchange('s/(\w[a-z]*)(\d*)/$1_$2/i',1,name)  into: newn separated by ' ' from dictionary.columns where libname='WORK' and memname='HAVE' and type='num' order by type, name;
select prxchange('s/(\w[a-z]*)(\d*)/$1_$2/i',1,name)  into: newc separated by ' ' from dictionary.columns where libname='WORK' and memname='HAVE' and type='char' order by type, name;
quit;
%put &amp;amp;chars &amp;amp;nums &amp;amp;newn &amp;amp;newc;

data want;
    set have;
    array var1(*) &amp;amp;chars;
    array var2(*) &amp;amp;nums;
    array var3(*) $100. &amp;amp;newn;
     array var4(*) $100. &amp;amp;newc;
     do i = 1 to dim(var1);
     var4(i)=catx(' - ', vname(var1(i)), var1(i));
          end;
     do i = 1 to dim(var2);
     var3(i)=catx(' - ', vname(var2(i)), var2(i));
          end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Sep 2019 12:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586400#M14472</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-05T12:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586629#M14537</link>
      <description>&lt;P&gt;Thanks Jag for the solution!!!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 06:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586629#M14537</guid>
      <dc:creator>hs71</dc:creator>
      <dc:date>2019-09-06T06:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Use header name in the rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586642#M14539</link>
      <description>Good to know, If you are satisfied with the solution and if it actually worked could you mark this solution as accepted so it will help other sas community users.</description>
      <pubDate>Fri, 06 Sep 2019 07:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Use-header-name-in-the-rows/m-p/586642#M14539</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-06T07:10:54Z</dc:date>
    </item>
  </channel>
</rss>

