<?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: Grouping of Ids in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57812#M12519</link>
    <description>Your description mentions "id2" but there is no such variable/column in your input or output/final data.  Focus on explaining with SAS variable names as you have provided what should be input data and output results.  I still believe that if you do some reading on DATA step programming and the references provided, it may help with your personal SAS programming development to learn and compose a SAS solution to your problem.  Ideally this is a forum for learning, not just getting answers from others in the form of program code.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Fri, 24 Jul 2009 11:51:34 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-07-24T11:51:34Z</dc:date>
    <item>
      <title>Grouping of Ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57808#M12515</link>
      <description>Hello Sir/Madam,&lt;BR /&gt;
&lt;BR /&gt;
Here is the sample data.I want to group together id's together based&lt;BR /&gt;
on the value of id2 and finally have an idnew which will have the value&lt;BR /&gt;
of the latest year's id as the final id value.I have tried to&lt;BR /&gt;
illustrate with an example below.I have just shown the grouping for&lt;BR /&gt;
one case it has to be the same everywhere and the id pertaining to the&lt;BR /&gt;
latest year should be populated elsewhere (like 93693 is the id for&lt;BR /&gt;
2003 that is why the new id has this value everywhere).Hope I will get&lt;BR /&gt;
answers to this unique problem.&lt;BR /&gt;
&lt;BR /&gt;
data ttt;&lt;BR /&gt;
infile cards truncover;&lt;BR /&gt;
input year id $ id1 $;&lt;BR /&gt;
cards;&lt;BR /&gt;
1999 8888&lt;BR /&gt;
2000 66789 96876&lt;BR /&gt;
2003 93693 42541&lt;BR /&gt;
1996 78965 78545&lt;BR /&gt;
2002 42541&lt;BR /&gt;
2000 7796 8888&lt;BR /&gt;
2001 42541 7796&lt;BR /&gt;
2005 7798&lt;BR /&gt;
2005 7798 1245&lt;BR /&gt;
2004 4472 6668&lt;BR /&gt;
2005 63373 737373&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
This is the sample data&lt;BR /&gt;
Year id	id1&lt;BR /&gt;
1999 8888&lt;BR /&gt;
2000 66789 96876&lt;BR /&gt;
2003 93693 42541&lt;BR /&gt;
2003 65574 64647&lt;BR /&gt;
1996 78965 78545&lt;BR /&gt;
2004 64647 63373&lt;BR /&gt;
2002 42541&lt;BR /&gt;
2000 7796 8888&lt;BR /&gt;
2001 42541 7796&lt;BR /&gt;
2005 7798&lt;BR /&gt;
2005 7798 1245&lt;BR /&gt;
2004 4472 6668&lt;BR /&gt;
2005 63373 737373&lt;BR /&gt;
&lt;BR /&gt;
Final Output&lt;BR /&gt;
&lt;BR /&gt;
Year  id	    id1	idnew&lt;BR /&gt;
&lt;BR /&gt;
2003  93693  42541	93693&lt;BR /&gt;
2002  42541 	93693&lt;BR /&gt;
2001  42541  7796	93693&lt;BR /&gt;
2000  7796    8888	93693&lt;BR /&gt;
1999  8888 	93693&lt;BR /&gt;
&lt;BR /&gt;
2005 737373 63373   737373&lt;BR /&gt;
2004 63373   64647  737373&lt;BR /&gt;
2003 64647   65574  737373&lt;BR /&gt;
&lt;BR /&gt;
so on and so forth.........&lt;BR /&gt;
&lt;BR /&gt;
Similarly other groups should be created in the same data.</description>
      <pubDate>Thu, 23 Jul 2009 04:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57808#M12515</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-23T04:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping of Ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57809#M12516</link>
      <description>A DATA step will work here - after sorting your data file first in sequence using a BY variable list of your choice.  &lt;BR /&gt;
&lt;BR /&gt;
To "RETAIN" a running list of related variable values, you must declare a new SAS character variable of suitable "LENGTH" and then in the DATA step, use SAS FIRST.&lt;BREAK_VARIABLE&gt;  (the last variable in your BY list) to initialize your value-list variable and also LAST.&lt;BREAK_VARIABLE&gt; to output your new SAS file/observation.  &lt;BR /&gt;
&lt;BR /&gt;
Since you must concatenate each related input observation to your "running list" variable, you will want to use a DATA step function like CATT / CATX / TRIM as you build your string of values.&lt;BR /&gt;
&lt;BR /&gt;
The SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;   website has SAS-hosted documentation (HTML-format and PDF documents) and supplemental technical / conference papers.  Also you can use the SEARCH facility to locate a related topic-oriented paper on the subject.  A few are provided below for reference and review.&lt;BR /&gt;
&lt;BR /&gt;
For what it's worth, here is a Google advanced search argument which can help you locate documents and other references on the SAS.COM domain/site:&lt;BR /&gt;
&lt;BR /&gt;
data step programming site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
DATA Step Processing&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
How the DATA Step Identifies BY Groups&lt;BR /&gt;
Processing Observations in a BY Group &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000761931.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000761931.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
A Hands-On Introduction to SAS® DATA Step Programming&lt;BR /&gt;
Debbie Buck, D. B. &amp;amp; P. Associates, Houston, TX&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/134-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/134-30.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Advanced DATA Step Topics&lt;BR /&gt;
Neil Howard, Independent Consultant, Charlottesville, VA&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi24/Advtutor/p47-24.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi24/Advtutor/p47-24.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.sas.com/offices/NA/canada/newsletter/insights/Sept08/SUGI99.pdf" target="_blank"&gt;http://www.sas.com/offices/NA/canada/newsletter/insights/Sept08/SUGI99.pdf&lt;/A&gt;&lt;BR /&gt;
The RETAIN Statement: One Window into the SASâ Data Step&lt;BR /&gt;
Paul Gorrell, Westat, Rockville, MD&lt;/BREAK_VARIABLE&gt;&lt;/BREAK_VARIABLE&gt;</description>
      <pubDate>Thu, 23 Jul 2009 10:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57809#M12516</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-23T10:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping of Ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57810#M12517</link>
      <description>Sir,&lt;BR /&gt;
&lt;BR /&gt;
Please read the post carefully it is beyond retaining a value.I want to co-relate the id based on a old id value and then group them together and then finally have a variable which will have the latest years value as its value through out.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Sachin</description>
      <pubDate>Fri, 24 Jul 2009 06:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57810#M12517</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-24T06:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping of Ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57811#M12518</link>
      <description>Hello snair1981.&lt;BR /&gt;
&lt;BR /&gt;
Could you please clarify the problem?&lt;BR /&gt;
Because what you described don't match with the sample data.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; data ttt;&lt;BR /&gt;
&amp;gt; infile cards truncover;&lt;BR /&gt;
&amp;gt; input year id $ id1 $;&lt;BR /&gt;
&amp;gt; cards;&lt;BR /&gt;
&amp;gt; 1999 8888&lt;BR /&gt;
&amp;gt; 2000 66789 96876&lt;BR /&gt;
&amp;gt; 2003 93693 42541&lt;BR /&gt;
&amp;gt; 1996 78965 78545&lt;BR /&gt;
&amp;gt; 2002 42541&lt;BR /&gt;
&amp;gt; 2000 7796 8888&lt;BR /&gt;
&amp;gt; 2001 42541 7796&lt;BR /&gt;
&amp;gt; 2005 7798&lt;BR /&gt;
&amp;gt; 2005 7798 1245&lt;BR /&gt;
&amp;gt; 2004 4472 6668&lt;BR /&gt;
&amp;gt; 2005 63373 737373&lt;BR /&gt;
&amp;gt; ;&lt;BR /&gt;
&lt;BR /&gt;
First, the above code will not produce the data bellow (imissing some rows).&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; This is the sample data&lt;BR /&gt;
&amp;gt; Year id	id1&lt;BR /&gt;
&amp;gt; 1999 8888&lt;BR /&gt;
&amp;gt; 2000 66789 96876&lt;BR /&gt;
&amp;gt; 2003 93693 42541&lt;BR /&gt;
&amp;gt; 2003 65574 64647&lt;BR /&gt;
&amp;gt; 1996 78965 78545&lt;BR /&gt;
&amp;gt; 2004 64647 63373&lt;BR /&gt;
&amp;gt; 2002 42541&lt;BR /&gt;
&amp;gt; 2000 7796 8888&lt;BR /&gt;
&amp;gt; 2001 42541 7796&lt;BR /&gt;
&amp;gt; 2005 7798&lt;BR /&gt;
&amp;gt; 2005 7798 1245&lt;BR /&gt;
&amp;gt; 2004 4472 6668&lt;BR /&gt;
&amp;gt; 2005 63373 737373&lt;BR /&gt;
&lt;BR /&gt;
Then...&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Final Output&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Year  id	    id1	idnew&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 2003  93693  42541	93693&lt;BR /&gt;
&amp;gt; 2002  42541 	93693&lt;BR /&gt;
&amp;gt; 2001  42541  7796	93693&lt;BR /&gt;
&amp;gt; 2000  7796    8888	93693&lt;BR /&gt;
&amp;gt; 1999  8888 	93693&lt;BR /&gt;
&lt;BR /&gt;
OK for the above group, but...&lt;BR /&gt;
 &lt;BR /&gt;
&amp;gt; 2005 737373 63373   737373&lt;BR /&gt;
&amp;gt; 2004 63373   64647  737373&lt;BR /&gt;
&amp;gt; 2003 64647   65574  737373&lt;BR /&gt;
&lt;BR /&gt;
Here id's are swapped from original sample...&lt;BR /&gt;
&lt;BR /&gt;
So...&lt;BR /&gt;
Should the data be paired then pairs should be swapped and paired again?!?&lt;BR /&gt;
&lt;BR /&gt;
Could you please be more specific about your task?&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Fri, 24 Jul 2009 10:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57811#M12518</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-24T10:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping of Ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57812#M12519</link>
      <description>Your description mentions "id2" but there is no such variable/column in your input or output/final data.  Focus on explaining with SAS variable names as you have provided what should be input data and output results.  I still believe that if you do some reading on DATA step programming and the references provided, it may help with your personal SAS programming development to learn and compose a SAS solution to your problem.  Ideally this is a forum for learning, not just getting answers from others in the form of program code.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 24 Jul 2009 11:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-of-Ids/m-p/57812#M12519</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-24T11:51:34Z</dc:date>
    </item>
  </channel>
</rss>

