<?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 query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674698#M203188</link>
    <description>&lt;P&gt;Then you need this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
set a;
by team post;
if first.team
then do;
  if post = "a3"
  then seq = 1;
  else seq = 0;
end;
else seq + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Aug 2020 11:51:22 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-08-05T11:51:22Z</dc:date>
    <item>
      <title>SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674684#M203181</link>
      <description>&lt;P&gt;The below program generated correct output for T1 to T3, but not T4.&amp;nbsp; Seq for post a3 should never start with 0, seq for post a3 should always start with 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone can help? Thanks.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data a;&lt;BR /&gt;input id $3. team $4. post $4.;&lt;BR /&gt;datalines;&lt;BR /&gt;101 t1 a2&lt;BR /&gt;102 t1 a3&lt;BR /&gt;200 t2 a2&lt;BR /&gt;201 t2 a3&lt;BR /&gt;300 t3 a2&lt;BR /&gt;301 t3 a3&lt;BR /&gt;302 t3 a3&lt;BR /&gt;400 t4 a3&lt;BR /&gt;401 t4 a3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;set a;&lt;BR /&gt;by team post;&lt;BR /&gt;seq+1;&lt;BR /&gt;if first.team then seq=0;&lt;BR /&gt;proc sort; by team post seq;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 10:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674684#M203181</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2020-08-05T10:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674686#M203182</link>
      <description>&lt;P&gt;Switched the order of two lines &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;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    input id $3. team $4. post $4.;
    datalines;
100 t1 a1
101 t1 a2
102 t1 a3
200 t2 a2
201 t2 a3
300 t3 a2
301 t3 a3
302 t3 a3
400 t4 a3
401 t4 a3
;
run;

data a;
    set a;
    by team post;
    if first.team then seq=0;
    seq+1;
run;

proc sort;
    by team post seq;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Aug 2020 10:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674686#M203182</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-08-05T10:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674689#M203184</link>
      <description>&lt;P&gt;I am sorry that I should have taken the id 100 out.&amp;nbsp; Post a2 should always start with 0; and post a3 should always start with 1.&amp;nbsp; T1 to T3 is correct, but I need help for T4.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;input id $3. team $4. post $4.;&lt;BR /&gt;datalines;&lt;BR /&gt;101 t1 a2&lt;BR /&gt;102 t1 a3&lt;BR /&gt;200 t2 a2&lt;BR /&gt;201 t2 a3&lt;BR /&gt;300 t3 a2&lt;BR /&gt;301 t3 a3&lt;BR /&gt;302 t3 a3&lt;BR /&gt;400 t4 a3&lt;BR /&gt;401 t4 a3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;set a;&lt;BR /&gt;by team post;&lt;/P&gt;
&lt;P&gt;seq+1;&lt;BR /&gt;if first.team then seq=0;&lt;BR /&gt;proc sort; by team post seq;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 10:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674689#M203184</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2020-08-05T10:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674697#M203187</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Still the idea of "T1 to T3 is correct, but I need help for T4" isn't clear,&lt;BR /&gt;but if following condition is true, here is a program.&lt;/P&gt;&lt;P&gt;1. Post a2 should always start with 0; and post a3 should always start with 1.&lt;BR /&gt;2. Condition 1 should always be carried on to entire obs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* initial data */
data have;
input id $3. team $4. post $4.;
datalines;
101 t1 a2
102 t1 a3
200 t2 a2
201 t2 a3
300 t3 a2
301 t3 a3
302 t3 a3
400 t4 a3
401 t4 a3
;
run;

data want;
	set have;
		by team
		   post;
/* 	retain statement to hold previous value */
	retain seq 0;
	if first.team 
		then 
			seq=0;
	else 
		seq+1;
/* Post a2 should always start with 0; and post a3 should always start with 1. */
/* 	ok case selection for a2 and a3 case	 */
	select (post);
		when ("a2") 
			seq=0;
		when ("a3") 
			seq=1;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Aug 2020 11:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674697#M203187</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-08-05T11:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674698#M203188</link>
      <description>&lt;P&gt;Then you need this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
set a;
by team post;
if first.team
then do;
  if post = "a3"
  then seq = 1;
  else seq = 0;
end;
else seq + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Aug 2020 11:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/674698#M203188</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T11:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/675167#M203389</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $3. team $4. post $4.;
datalines;
101 t1 a2
102 t1 a3
200 t2 a2
201 t2 a3
300 t3 a2
301 t3 a3
302 t3 a3
400 t4 a3
401 t4 a3
;
run;

data want;
	set have;
		by team
		   post;
	seq+1;
	if first.team then do;
			if post="a3" then seq=1;
			else seq=0;
		end;
	else if post="a2" then seq=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 23:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/675167#M203389</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-08-06T23:54:18Z</dc:date>
    </item>
  </channel>
</rss>

