<?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: To transpose and add new row using column name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581918#M13767</link>
    <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type $ group $ new_201803 exist_201803 new_201804 exist_201804;
datalines;
A Employer 15 21 10 36
A Employee 20 17 22 37
B Employer 2 8 10 10
B Employee 13 20 7 33
;

proc sort data=have;
	by type group;
run;

proc transpose data=have out=temp;
   by type group;
run;

data want;
	format type group month tag amount;
	set temp;
	rename COL1=Amount;
	month=input(compress(_NAME_, '', 'kd'), best.);
	tag=compress(_NAME_, '_', 'd');
	drop _NAME_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 17 Aug 2019 11:59:00 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-08-17T11:59:00Z</dc:date>
    <item>
      <title>To transpose and add new row using column name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581910#M13764</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help here.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have this data. I would like to add another 2 columns which is month and tag for 'new' and 'exist' value based on the column name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;type | group  | new_201803 | exist_201803 | new_201804 | exist_201804|
A    |Employer|          15|            21|          10|           36|
A    |Employee|          20|            17|          22|           37|&lt;BR /&gt;B    |Employer|           2|             8|          10|           10|&lt;BR /&gt;B    |Employee|          13|            20|           7|           33|&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Expected data is like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;type | group  |month  |tag        | amount|
A    |Employer|201803 |        new|     15|&lt;BR /&gt;A    |Employer|201803 |      exist|     21|&lt;BR /&gt;A    |Employer|201804 |        new|     10|&lt;BR /&gt;A    |Employer|201804 |      exist|     36|
A    |Employee|201803 |        new|     20|&lt;BR /&gt;A    |Employee|201803 |      exist|     17|
A    |Employee|201804 |        new|     22|&lt;BR /&gt;A    |Employee|201804 |      exist|     37|
B    |Employer|201803 |        new|      2|&lt;BR /&gt;B    |Employer|201803 |      exist|      8|&lt;BR /&gt;B    |Employer|201804 |        new|     10|&lt;BR /&gt;B    |Employer|201804 |      exist|     10|&lt;BR /&gt;B    |Employee|201803 |        new|     13|&lt;BR /&gt;B    |Employee|201803 |      exist|     20|&lt;BR /&gt;B    |Employee|201804 |        new|      7|&lt;BR /&gt;B    |Employee|201804 |      exist|     33|&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Currently I just arranged them in manual way. I would like to use Code but don't know where to start.&lt;/P&gt;&lt;P&gt;Using script can allow me arranging bigger table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 09:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581910#M13764</guid>
      <dc:creator>dearkyr</dc:creator>
      <dc:date>2019-08-17T09:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: To transpose and add new row using column name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581918#M13767</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type $ group $ new_201803 exist_201803 new_201804 exist_201804;
datalines;
A Employer 15 21 10 36
A Employee 20 17 22 37
B Employer 2 8 10 10
B Employee 13 20 7 33
;

proc sort data=have;
	by type group;
run;

proc transpose data=have out=temp;
   by type group;
run;

data want;
	format type group month tag amount;
	set temp;
	rename COL1=Amount;
	month=input(compress(_NAME_, '', 'kd'), best.);
	tag=compress(_NAME_, '_', 'd');
	drop _NAME_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Aug 2019 11:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581918#M13767</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-17T11:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: To transpose and add new row using column name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581920#M13769</link>
      <description>&lt;P&gt;Alternatively&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type $ group $ new_201803 exist_201803 new_201804 exist_201804;
datalines;
A Employer 15 21 10 36
A Employee 20 17 22 37
B Employer 2 8 10 10
B Employee 13 20 7 33
;

data want(keep=type group month tag amount);
	set have;
	array _{*} _numeric_;
	do i=1 to dim(_);
		tag=compress(vname(_[i]), '_', 'd');
		month=input(compress(vname(_[i]), '', 'kd'), best.);
		amount=_[i];
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Aug 2019 12:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581920#M13769</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-17T12:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: To transpose and add new row using column name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581933#M13771</link>
      <description>&lt;P&gt;If you had a combination of variables that uniquely identified the row then you could use PROC TRANSPOSE.&lt;/P&gt;
&lt;P&gt;Use those variables in your BY statement for PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=step2 ;
  by type group ;
  var new_: exist_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can parse the _NAME_ field to get the two pieces of information out of that metadata and into actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set step2;
  length month 8 tag $8  ;
  tag=scan(_name_,1,'_');
  month = input(scan(_name_,2,'_'),yymmn6.);
  format month yymm7.;
  rename col1=amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't have unique BY groups then you could just add a step to create a new variable to uniquely id each row.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  row + 1;
  set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use that in your BY statement for PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=step1 out=step2 ;
  by row type group ;
  var new_: exist_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 15:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-transpose-and-add-new-row-using-column-name/m-p/581933#M13771</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-17T15:13:28Z</dc:date>
    </item>
  </channel>
</rss>

