<?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 transposing to make one record per id. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483391#M286951</link>
    <description>&lt;P&gt;Hi everyone, I have a dataset that looks roughly like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data have;&lt;BR /&gt;Input ID Year Num_visits;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2011 3&lt;BR /&gt; . 2012 2&lt;BR /&gt; . 2013 0&lt;BR /&gt; . 2014 4 &lt;BR /&gt;2 2011 2&lt;BR /&gt; . 2012 3&lt;BR /&gt; . 2013 1&lt;BR /&gt; . 2014 0&lt;BR /&gt;3 2011 6&lt;BR /&gt; . 2012 0&lt;BR /&gt; . 2013 2&lt;BR /&gt; . 2014 5 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;What I'm trying to do is convert that into a dataset that looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Patient ID&amp;nbsp; &amp;nbsp; &amp;nbsp; 2011&amp;nbsp; &amp;nbsp; &amp;nbsp;2012&amp;nbsp; &amp;nbsp; &amp;nbsp;2013&amp;nbsp; &amp;nbsp; &amp;nbsp;2014&amp;nbsp; &amp;nbsp;Total&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any thoughts would be much appreciated!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks so much&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Mike&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Aug 2018 14:02:39 GMT</pubDate>
    <dc:creator>righcoastmike</dc:creator>
    <dc:date>2018-08-02T14:02:39Z</dc:date>
    <item>
      <title>transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483391#M286951</link>
      <description>&lt;P&gt;Hi everyone, I have a dataset that looks roughly like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data have;&lt;BR /&gt;Input ID Year Num_visits;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2011 3&lt;BR /&gt; . 2012 2&lt;BR /&gt; . 2013 0&lt;BR /&gt; . 2014 4 &lt;BR /&gt;2 2011 2&lt;BR /&gt; . 2012 3&lt;BR /&gt; . 2013 1&lt;BR /&gt; . 2014 0&lt;BR /&gt;3 2011 6&lt;BR /&gt; . 2012 0&lt;BR /&gt; . 2013 2&lt;BR /&gt; . 2014 5 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;What I'm trying to do is convert that into a dataset that looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Patient ID&amp;nbsp; &amp;nbsp; &amp;nbsp; 2011&amp;nbsp; &amp;nbsp; &amp;nbsp;2012&amp;nbsp; &amp;nbsp; &amp;nbsp;2013&amp;nbsp; &amp;nbsp; &amp;nbsp;2014&amp;nbsp; &amp;nbsp;Total&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any thoughts would be much appreciated!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks so much&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Mike&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 14:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483391#M286951</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2018-08-02T14:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483399#M286952</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input ID Year Num_visits;
datalines;
1 2011 3
 . 2012 2
 . 2013 0
 . 2014 4 
2 2011 2
 . 2012 3
 . 2013 1
 . 2014 0
3 2011 6
 . 2012 0
 . 2013 2
 . 2014 5 
;
run;

data _have;
set have;
retain _id;
if id then _id=id;
else id=_id;
drop _id;
run;

proc transpose data=_have out=want prefix=year;
by id;
id year;
var num_visits;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Aug 2018 14:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483399#M286952</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-02T14:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483401#M286953</link>
      <description>&lt;P&gt;Well, the simple answer is don't.&amp;nbsp; First off transposed datasets are far more difficult to program with.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you may want this for an output pdf or something - which is the only place transposed datasets are more useful is to the viewer - so first you need to populate id across records:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have (rename=(id=old_id));
  retain id;
  if old_id ne . then id=old_id;
run;&lt;/PRE&gt;
&lt;P&gt;Next, proc transpose:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=want out=want2;
  by id;
  var num_visits;
  id year;
run;&lt;/PRE&gt;
&lt;P&gt;Then add your total in a datastep.&amp;nbsp; You may also be able to use tabulate procedure to get the output.&lt;/P&gt;
&lt;P&gt;I would still suggest you do not transpose unless needed to for an output, work with what you have (and always populate id!).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 14:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483401#M286953</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-02T14:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483402#M286954</link>
      <description>&lt;P&gt;If you want a table, then PROC REPORT will make a table like this with ease.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a data set for analysis, most cases transposing your data to have variable names 2011, 2012, etc. is not a good idea (and furthermore variable names can't begin with a digit).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 14:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483402#M286954</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-02T14:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483409#M286955</link>
      <description>&lt;P&gt;Thanks everyone, and your warning about transposing is well taken.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this point it's just a clearer way for me to get a sense of what I'm looking at.&amp;nbsp; I have a huge dataset so 5 records per person get's very cumbersome very quickly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always, you have been a huge help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 14:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483409#M286955</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2018-08-02T14:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483414#M286957</link>
      <description>&lt;P&gt;something like below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;run;

Data have(rename=(newid=id));
retain newid;
Input ID Year Num_visits;
if id ne . then newid = id;
drop id;
datalines;
1 2011 3
 . 2012 2
 . 2013 0
 . 2014 4 
2 2011 2
 . 2012 3
 . 2013 1
 . 2014 0
3 2011 6
 . 2012 0
 . 2013 2
 . 2014 5 
;

proc transpose data= have out=have1(drop=_name_);
by id;
id year;
var num_visits;
run;

data want;
set have1;
total =sum('2011'n,'2012'n,'2013'n,'2014'n);
run&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Aug 2018 14:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483414#M286957</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-08-02T14:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: transposing to make one record per id.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483563#M286958</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone, I have a dataset that looks roughly like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data have;&lt;BR /&gt;Input ID Year Num_visits;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2011 3&lt;BR /&gt; . 2012 2&lt;BR /&gt; . 2013 0&lt;BR /&gt; . 2014 4 &lt;BR /&gt;2 2011 2&lt;BR /&gt; . 2012 3&lt;BR /&gt; . 2013 1&lt;BR /&gt; . 2014 0&lt;BR /&gt;3 2011 6&lt;BR /&gt; . 2012 0&lt;BR /&gt; . 2013 2&lt;BR /&gt; . 2014 5 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;What I'm trying to do is convert that into a dataset that looks like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Patient ID&amp;nbsp; &amp;nbsp; &amp;nbsp; 2011&amp;nbsp; &amp;nbsp; &amp;nbsp;2012&amp;nbsp; &amp;nbsp; &amp;nbsp;2013&amp;nbsp; &amp;nbsp; &amp;nbsp;2014&amp;nbsp; &amp;nbsp;Total&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any thoughts would be much appreciated!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks so much&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Mike&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000" size="4"&gt;Big red flag: &lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#ff0000" size="4"&gt;&lt;FONT color="#000000" size="3"&gt;Any variable such as ID that should be identifying every record and has missing values will come back at some time in the future and cause problems. One of the first things for data quality purposes is to ensure such things. Imagine a bank trying to add/subtract money in an account without the account id?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 19:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-to-make-one-record-per-id/m-p/483563#M286958</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-02T19:53:56Z</dc:date>
    </item>
  </channel>
</rss>

