<?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 How do I build a variable that is the Nth Value of the ID? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260574#M50587</link>
    <description>&lt;P&gt;I have a dataset that has account change information, and I want to build a summary table that allows me to see what those changes were over time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Table looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Date email_address&lt;/P&gt;&lt;P&gt;josh 1/1/2015 josh1@gmail.com&lt;/P&gt;&lt;P&gt;josh 1/2/2015 josh2@yahoo.com&lt;/P&gt;&lt;P&gt;josh 1/3/2015 josh3@yahoo.com&lt;/P&gt;&lt;P&gt;mary 1/1/2015 mary123@aol.com&lt;/P&gt;&lt;P&gt;mary 1/15/2015 mars@blah.com&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the output to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Most_recent_date email_address1 email_address2 email_address3&lt;/P&gt;&lt;P&gt;josh 1/3/2015 josh3@yahoo.com josh2@yahoo.com josh1@gmail.com&lt;/P&gt;&lt;P&gt;mary 1/15/2015 mars@blah.com mary123@aol.com .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone had experience working with this?&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2016 22:03:04 GMT</pubDate>
    <dc:creator>JS</dc:creator>
    <dc:date>2016-03-31T22:03:04Z</dc:date>
    <item>
      <title>How do I build a variable that is the Nth Value of the ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260574#M50587</link>
      <description>&lt;P&gt;I have a dataset that has account change information, and I want to build a summary table that allows me to see what those changes were over time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Table looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Date email_address&lt;/P&gt;&lt;P&gt;josh 1/1/2015 josh1@gmail.com&lt;/P&gt;&lt;P&gt;josh 1/2/2015 josh2@yahoo.com&lt;/P&gt;&lt;P&gt;josh 1/3/2015 josh3@yahoo.com&lt;/P&gt;&lt;P&gt;mary 1/1/2015 mary123@aol.com&lt;/P&gt;&lt;P&gt;mary 1/15/2015 mars@blah.com&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the output to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Most_recent_date email_address1 email_address2 email_address3&lt;/P&gt;&lt;P&gt;josh 1/3/2015 josh3@yahoo.com josh2@yahoo.com josh1@gmail.com&lt;/P&gt;&lt;P&gt;mary 1/15/2015 mars@blah.com mary123@aol.com .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone had experience working with this?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260574#M50587</guid>
      <dc:creator>JS</dc:creator>
      <dc:date>2016-03-31T22:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I build a variable that is the Nth Value of the ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260575#M50588</link>
      <description>&lt;P&gt;Long to wide via&amp;nbsp;Proc transpose or an array.&lt;/P&gt;
&lt;P&gt;I swear this gets asked multiple times a day here &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;Search here, google, or someone else will probably answer it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't know the max amount of email addresses per person, proc transpose is more dynamic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260575#M50588</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-31T22:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I build a variable that is the Nth Value of the ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260576#M50589</link>
      <description>&lt;P&gt;Knowing where to look is half the battle sometimes (:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the input, and I'll take a look at Proc Transpose.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260576#M50589</guid>
      <dc:creator>JS</dc:creator>
      <dc:date>2016-03-31T22:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I build a variable that is the Nth Value of the ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260577#M50590</link>
      <description>&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/longtowide_data.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/longtowide_data.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/ltow_transpose.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/ltow_transpose.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My go to references/links.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260577#M50590</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-31T22:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I build a variable that is the Nth Value of the ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260578#M50591</link>
      <description>&lt;P&gt;This works for your example data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat id $6. date mmddyy. email_address $25.;
   format date mmddyy10.;
input ID Date email_address;
datalines;
josh 1/1/2015 josh1@gmail.com
josh 1/2/2015 josh2@yahoo.com
josh 1/3/2015 josh3@yahoo.com
mary 1/1/2015 mary123@aol.com
mary 1/15/2015 mars@blah.com
run;

proc sort data=have; by id date;run;
proc transpose data=have out=temp (drop=_name_ )
      prefix=email_address;
   by id;
   Var email_address;
run;

proc sql;
   create table want as
   select a.*, b.Most_recent_date
   from temp as a left join 
      (select id, max(date) as Most_recent_date format=mmddyy10. from have
       group by id) as b
   on a.id = b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Minor trickyness involved because of wanting the max date and order of naming the emails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260578#M50591</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-31T22:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I build a variable that is the Nth Value of the ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260581#M50592</link>
      <description>&lt;P&gt;This is literally EXACTLY the correct solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd gone down a dark path and tried to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;if have.id&amp;nbsp;then seq_id=0;&lt;BR /&gt;seq_id+1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... and then build out a separate table for each one of the variables, but this Proc Transpose example you've provided is fantastic.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 22:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-build-a-variable-that-is-the-Nth-Value-of-the-ID/m-p/260581#M50592</guid>
      <dc:creator>JS</dc:creator>
      <dc:date>2016-03-31T22:57:01Z</dc:date>
    </item>
  </channel>
</rss>

