<?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: List First week and Last week? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906349#M357880</link>
    <description>&lt;P&gt;Proc summary:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
   class state;
   var week;
   output out=want (drop=_:) min(week)=week_start max(week)=week_end;
run;&lt;/PRE&gt;
&lt;P&gt;Some possible reasons to use proc summary/means:&lt;/P&gt;
&lt;P&gt;If you want to know how many weeks are represented don't drop the _freq_ variable that is normally included.&lt;/P&gt;
&lt;P&gt;If of interest much easier to add a "mean week" or median.&lt;/P&gt;
&lt;P&gt;If the data has observations missing week then asking for NMISS stat . Adding all that to a data step would be ugly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the desired output is just to see then use a report procedure.&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have f=best5.;
   class state;
   var week;
   table state,
           week=' '*(min='Week start' max='Week end')
   ;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 Dec 2023 21:39:31 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-12-05T21:39:31Z</dc:date>
    <item>
      <title>List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906330#M357871</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking for each state's first week and last week in the sample dataset.&amp;nbsp; Please help.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;  
	length State $5 Week 3; 
	infile datalines delimiter=','; 
	input State Week;  
	datalines;                     
	GA,2101,
	GA,2102,
	GA,2104,
	GA,2105,
	GA,2106,
	GA,2109,
	GA,2110,
	GA,2115,
	GA,2117,
	GA,2118,
	GA,2120,
	GA,2123,
	GA,2124,
	NV,2201,
	NV,2202,
	NV,2204,
	NV,2205,
	NV,2206,
	NV,2209,
	NV,2210,
	NV,2213,
;   

data want_week_1st_last;
	length State $5 Week_start 3  Week_end 3; 
	infile datalines delimiter=','; 
	input State  Week_start  Week_end;  
	datalines;  
	GA, 2101,2124,
	NV, 2201,2213,
;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2023 21:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906330#M357871</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-12-05T21:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906332#M357873</link>
      <description>&lt;P&gt;SQL is a good way to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table Want as
  select State
        ,min(Week) as Week_Start
        ,max(Week) as Week_End
  from Have
  group by State
  ;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2023 21:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906332#M357873</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-05T21:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906333#M357874</link>
      <description>I would like to do it in the data step</description>
      <pubDate>Tue, 05 Dec 2023 21:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906333#M357874</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-12-05T21:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906334#M357875</link>
      <description>&lt;P&gt;RETAIN week_start. Use BY state. Set week_start at first.state. Use last.state as condition in a subsetting if, and set week_end there.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 21:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906334#M357875</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-05T21:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906335#M357876</link>
      <description>&lt;P&gt;I would use first.variable and last.variable in BY-Groups.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	by state;
	if not (first.state or last.state) then delete;
	retain first_week last_week;
	if first.state then first_week=week;
	if last.state then last_week=week;
	if last.state; 
	drop week; 
proc print; run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 21:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906335#M357876</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-12-05T21:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906336#M357877</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I would like to do it in the data step&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 21:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906336#M357877</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-05T21:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906349#M357880</link>
      <description>&lt;P&gt;Proc summary:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
   class state;
   var week;
   output out=want (drop=_:) min(week)=week_start max(week)=week_end;
run;&lt;/PRE&gt;
&lt;P&gt;Some possible reasons to use proc summary/means:&lt;/P&gt;
&lt;P&gt;If you want to know how many weeks are represented don't drop the _freq_ variable that is normally included.&lt;/P&gt;
&lt;P&gt;If of interest much easier to add a "mean week" or median.&lt;/P&gt;
&lt;P&gt;If the data has observations missing week then asking for NMISS stat . Adding all that to a data step would be ugly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the desired output is just to see then use a report procedure.&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have f=best5.;
   class state;
   var week;
   table state,
           week=' '*(min='Week start' max='Week end')
   ;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2023 21:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906349#M357880</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-05T21:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: List First week and Last week?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906389#M357897</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321371"&gt;@A_Kh&lt;/a&gt;&amp;nbsp;you can get the result with less coding:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain state first_week end_week;
set have (rename=(week=end_week9);
by state;
if first.state then first_week = end_week;
if last.state;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Dec 2023 06:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-First-week-and-Last-week/m-p/906389#M357897</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-06T06:45:04Z</dc:date>
    </item>
  </channel>
</rss>

