<?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: SAS queries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-queries/m-p/741894#M231991</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80526"&gt;@scb&lt;/a&gt;&amp;nbsp;It's not clear to me what determines the "last team&amp;nbsp;&lt;SPAN&gt;he played for" for example, Paul appears to have played in teams 002, 003 &amp;amp; 004 in the last season 202103.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The following code does provide what you asked for in your output, but I'm not sure the code will provide what you want. For example if you add the input record 202104, PAUL, 003,002,10 then what would the output look like:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
	infile DATALINES DLM=',' DSD;
	INPUT SEASON PLAYER $ DIV $ TEAM $ TARGET;
	DATALINES;
202101, JOHN,003,001,10
202102, JOHN,003,001,15
202103, JOHN,003,001,16
202101, PAUL,003,002,20
202101, PAUL,003,003,20
202101, PAUL,003,004,20
202102, PAUL,003,002,25
202102, PAUL,003,003,25
202102, PAUL,003,004,25
202103, PAUL,003,002,35
202103, PAUL,003,003,35
202103, PAUL,003,004,35
202101, KENT,,005,42
202102, KENT,,005,45
202103, KENT,,005,46
;
RUN;
/*202104, PAUL,003,002,10*/

/* Sort data into an order that will work */
proc sort data=test out=srtdTest ;
	by player descending season descending team ;
run ;

data want ;
	set srtdTest ;
	by player descending season descending team ;
	/* If it's not the first occurance of season then set target to 0 */
	if not(first.season) then do ;	
		target=0 ;
	end ;
run ;

proc sort data=want out=srtdWant ;
	by player season team ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 17 May 2021 15:43:19 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2021-05-17T15:43:19Z</dc:date>
    <item>
      <title>SAS queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-queries/m-p/741865#M231982</link>
      <description>&lt;P&gt;I would like to have PAUL (played multiple teams) target or any player target that have played for multiple teams to be put in the last team he played for to avoid duplicate target.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone can help? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA TEST;&lt;BR /&gt;infile DATALINES DLM=',' DSD;&lt;BR /&gt;INPUT SEASON PLAYER $ DIV $ TEAM $ TARGET;&lt;BR /&gt;DATALINES;&lt;BR /&gt;202101, JOHN,003,001,10&lt;BR /&gt;202102, JOHN,003,001,15&lt;BR /&gt;202103, JOHN,003,001,16&lt;BR /&gt;202101, PAUL,003,002,20&lt;BR /&gt;202101, PAUL,003,003,20&lt;BR /&gt;202101, PAUL,003,004,20&lt;BR /&gt;202102, PAUL,003,002,25&lt;BR /&gt;202102, PAUL,003,003,25&lt;BR /&gt;202102, PAUL,003,004,25&lt;BR /&gt;202103, PAUL,003,002,35&lt;BR /&gt;202103, PAUL,003,003,35&lt;BR /&gt;202103, PAUL,003,004,35&lt;BR /&gt;202101, KENT,,005,42&lt;BR /&gt;202102, KENT,,005,45&lt;BR /&gt;202103, KENT,,005,46&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My desired output will be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Season&amp;nbsp; Player&amp;nbsp; &amp;nbsp;Div&amp;nbsp; &amp;nbsp;Team&amp;nbsp; &amp;nbsp;Target&lt;/P&gt;
&lt;P&gt;202101 JOHN&amp;nbsp; 003&amp;nbsp; &amp;nbsp; 001&amp;nbsp; 10&lt;BR /&gt;202102 JOHN 003&amp;nbsp; &amp;nbsp; 001&amp;nbsp; 15&lt;BR /&gt;202103 JOHN 003&amp;nbsp; &amp;nbsp; 001&amp;nbsp; 16&lt;BR /&gt;202101 PAUL 003 002&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;202101 PAUL 003 003&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;202101 PAUL 003 004&amp;nbsp; &amp;nbsp;20&lt;BR /&gt;202102 PAUL 003 002&amp;nbsp; 0&lt;BR /&gt;202102 PAUL 003 003&amp;nbsp; 0&lt;BR /&gt;202102 PAUL 003 004&amp;nbsp; 25&lt;BR /&gt;202103 PAUL 003 002 0&lt;BR /&gt;202103 PAUL 003 003 0&lt;BR /&gt;202103 PAUL 003 004 35&lt;BR /&gt;202101 KENT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 005 42&lt;BR /&gt;202102 KENT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 005 45&lt;BR /&gt;202103 KENT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 005 46&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 14:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-queries/m-p/741865#M231982</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2021-05-17T14:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-queries/m-p/741894#M231991</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80526"&gt;@scb&lt;/a&gt;&amp;nbsp;It's not clear to me what determines the "last team&amp;nbsp;&lt;SPAN&gt;he played for" for example, Paul appears to have played in teams 002, 003 &amp;amp; 004 in the last season 202103.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The following code does provide what you asked for in your output, but I'm not sure the code will provide what you want. For example if you add the input record 202104, PAUL, 003,002,10 then what would the output look like:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
	infile DATALINES DLM=',' DSD;
	INPUT SEASON PLAYER $ DIV $ TEAM $ TARGET;
	DATALINES;
202101, JOHN,003,001,10
202102, JOHN,003,001,15
202103, JOHN,003,001,16
202101, PAUL,003,002,20
202101, PAUL,003,003,20
202101, PAUL,003,004,20
202102, PAUL,003,002,25
202102, PAUL,003,003,25
202102, PAUL,003,004,25
202103, PAUL,003,002,35
202103, PAUL,003,003,35
202103, PAUL,003,004,35
202101, KENT,,005,42
202102, KENT,,005,45
202103, KENT,,005,46
;
RUN;
/*202104, PAUL,003,002,10*/

/* Sort data into an order that will work */
proc sort data=test out=srtdTest ;
	by player descending season descending team ;
run ;

data want ;
	set srtdTest ;
	by player descending season descending team ;
	/* If it's not the first occurance of season then set target to 0 */
	if not(first.season) then do ;	
		target=0 ;
	end ;
run ;

proc sort data=want out=srtdWant ;
	by player season team ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 15:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-queries/m-p/741894#M231991</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-05-17T15:43:19Z</dc:date>
    </item>
  </channel>
</rss>

