<?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: Transposing table and keeping first entry of a column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409176#M99955</link>
    <description>&lt;P&gt;Perhaps you could describe what you are going to do with the resultant dataset. It may be that the transformation is not even needed.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2017 15:25:48 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-10-31T15:25:48Z</dc:date>
    <item>
      <title>Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409150#M99949</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please I need help on how best to handle the following problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table in this format&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="5" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;COUNTRY&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;MONTH&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;MATHSCORE&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;ENGSCORE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;1&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;UK&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;1&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;UK&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;1&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;UK&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 24&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;2&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;US&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;2&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;US&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 18&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;3&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;FL&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;3&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;FL&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 18&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;3&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;FL&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 16&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;3&amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;FL&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 16&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output I want is&amp;nbsp; below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="880"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;ID&lt;/TD&gt;
&lt;TD width="64"&gt;COUNTRY&lt;/TD&gt;
&lt;TD width="64"&gt;MONTH&lt;/TD&gt;
&lt;TD width="92"&gt;MATHSCORE1&lt;/TD&gt;
&lt;TD width="92"&gt;MATHSCORE2&lt;/TD&gt;
&lt;TD width="92"&gt;MATHSCORE3&lt;/TD&gt;
&lt;TD width="92"&gt;MATHSCORE4&lt;/TD&gt;
&lt;TD width="80"&gt;ENGSCORE1&lt;/TD&gt;
&lt;TD width="80"&gt;ENGSCORE2&lt;/T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;P&gt;I could transpose for mathscore, then for engscore and then merge the data but my problem is how to keep just the month value for each of the id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 21:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409150#M99949</guid>
      <dc:creator>Teamtim</dc:creator>
      <dc:date>2017-10-31T21:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409173#M99954</link>
      <description>You can include multiple values in the BY and ID statements. 

Post the code you tried if you're having issues.</description>
      <pubDate>Tue, 31 Oct 2017 15:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409173#M99954</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-31T15:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409176#M99955</link>
      <description>&lt;P&gt;Perhaps you could describe what you are going to do with the resultant dataset. It may be that the transformation is not even needed.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 15:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409176#M99955</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-31T15:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409181#M99956</link>
      <description>&lt;PRE&gt;proc transpose data=have out=want (where=(not missing(_name_))) prefix=mathscore_;
  by id country;
  var mathscore;
  id month;
  copy month;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 15:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409181#M99956</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-10-31T15:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409300#M99981</link>
      <description />
      <pubDate>Tue, 31 Oct 2017 21:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409300#M99981</guid>
      <dc:creator>Teamtim</dc:creator>
      <dc:date>2017-10-31T21:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409303#M99982</link>
      <description>&lt;P&gt;data tic;&lt;BR /&gt;input id country$ month math;&lt;BR /&gt;datalines;&lt;BR /&gt;1 uk 1 10 &lt;BR /&gt;1 uk 2 15 &lt;BR /&gt;1 uk 3 24 &lt;BR /&gt;2 us 2 15 &lt;BR /&gt;2 us 4 12 &lt;BR /&gt;3 fl 1 15 &lt;BR /&gt;3 fl 2 16 &lt;BR /&gt;3 fl 3 17 &lt;BR /&gt;3 fl 4 15 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=tic;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; data tot(drop=month math);&lt;BR /&gt; retain month1-month4 math1-math4;&lt;BR /&gt;array tat{4} month1-month4;&lt;BR /&gt;array kat{4} math1-math4;&lt;BR /&gt;set tic;&lt;BR /&gt;by id;&lt;BR /&gt;if first.id then do;&lt;BR /&gt;i=1;&lt;BR /&gt;do j=1 to 4;&lt;BR /&gt;tat{j}=.;&lt;BR /&gt;kat{j}=.;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;tat(i)=month;&lt;BR /&gt;kat(i)=math;&lt;BR /&gt;if last.id then output;&lt;BR /&gt;i+1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;The observations are shifted to the left.I can't seem to have them in the proper cell.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 21:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409303#M99982</guid>
      <dc:creator>Teamtim</dc:creator>
      <dc:date>2017-10-31T21:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409304#M99983</link>
      <description>I want to use data step. See my code below but there is problem with the missing values&lt;BR /&gt;&lt;BR /&gt;data tic;&lt;BR /&gt;input id country$ month math;&lt;BR /&gt;datalines;&lt;BR /&gt;1 uk 1 10 &lt;BR /&gt;1 uk 2 15 &lt;BR /&gt;1 uk 3 24 &lt;BR /&gt;2 us 2 15 &lt;BR /&gt;2 us 4 12 &lt;BR /&gt;3 fl 1 15 &lt;BR /&gt;3 fl 2 16 &lt;BR /&gt;3 fl 3 17 &lt;BR /&gt;3 fl 4 15 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=tic;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt; data tot(drop=month math);&lt;BR /&gt; retain month1-month4 math1-math4;&lt;BR /&gt;array tat{4} month1-month4;&lt;BR /&gt;array kat{4} math1-math4;&lt;BR /&gt;set tic;&lt;BR /&gt;by id;&lt;BR /&gt;if first.id then do;&lt;BR /&gt;i=1;&lt;BR /&gt;do j=1 to 4;&lt;BR /&gt;tat{j}=.;&lt;BR /&gt;kat{j}=.;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;tat(i)=month;&lt;BR /&gt;kat(i)=math;&lt;BR /&gt;if last.id then output;&lt;BR /&gt;i+1;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 31 Oct 2017 21:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409304#M99983</guid>
      <dc:creator>Teamtim</dc:creator>
      <dc:date>2017-10-31T21:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409306#M99984</link>
      <description>You need to add a RETAIN statement and you need to set them all to missing each whenever you start a new group. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;</description>
      <pubDate>Tue, 31 Oct 2017 21:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409306#M99984</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-31T21:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing table and keeping first entry of a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409467#M100041</link>
      <description>&lt;PRE&gt;

data have;
infile cards expandtabs truncover;
input ID	COUNTRY $	MONTH	MATHSCORE	ENGSCORE ;
cards;
1   	UK	1	     10         	      3
1   	UK	2	     15         	      8
1   	UK	3	      24       	       7
2   	US	2	      15       	      10
2   	US	4	      12       	      18
3   	FL	1	        15       	     15
3   	FL	2	       16       	      18
3   	FL	3	        17       	      16
3   	FL	4	        15       	      16
;
run;

proc sql noprint;
select max(n) into : n
 from (select count(*) as n from have group by id);
quit;

proc summary data=have;
by id country;
output out=temp(drop=_type_ _freq_) idgroup(out[&amp;amp;n] (MATHSCORE ENGSCORE)=);
run;

data temp1;
 set have(keep=id country month);
 by id country;
 if first.country;
run;
data want;
 merge temp1 temp;
 by id country;
run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Nov 2017 14:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-table-and-keeping-first-entry-of-a-column/m-p/409467#M100041</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-01T14:01:24Z</dc:date>
    </item>
  </channel>
</rss>

