<?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: Need help on where to even start please in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665250#M198881</link>
    <description>&lt;P&gt;In case DAY contains a date then you can use next code.&lt;/P&gt;
&lt;P&gt;I have created a dummy test data-set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
     do ID = 1 to 5;
	    do DAY = '01JAN2020'd to '28FEB2020'd;
		   destas = 100*ranuni(0);
		   output;
		 end;
	end;
	format destas 5.2;
run;

proc sql noprint;
   select min(DAY), max(DAY) into :DayStart, :DayEnd 
     from test;
quit;
%put DayStart=&amp;amp;daystart  DayEnd = &amp;amp;dayend;

data cntl;
     retain fmtname 'week';
     do date = &amp;amp;DayStart to &amp;amp;DayEnd;
        week = int((date - &amp;amp;dayStart)/7 +1);
        end = date;
        label = put(week,2.);
        output;
     end;
     rename date = start;
run;
proc format lib=work cntlin=cntl; run;

proc means data=test nway noprint;
  class ID DAY;
  var destas;
  output out=want(rename=(_freq_ = DAYS) drop=_type_)
         sum=SumDestas  mean=AvgDestas;
  format day week. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 26 Jun 2020 06:52:41 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-06-26T06:52:41Z</dc:date>
    <item>
      <title>Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665230#M198869</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I posted what i have to accomplish.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The part i am confused about is where do i even start with this program? And how would i start&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This assignment needs to have 912 rows when it is done and right now it has 6384. I have to set it up all in one row for each week. For example each ID has 84 days and i have to have a week column and for every 7 days it should say week 1 or week 2, etc. And there is a total of 76 IDs. so 76*12=912 rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this text is confusing a little. Here is an example of how it needs to be set up&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(76 total)&amp;nbsp; &amp;nbsp; &amp;nbsp;(There is 84 days so should be 12 weeks each ID)&lt;/P&gt;&lt;P&gt;ID.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Week.&amp;nbsp; &amp;nbsp; &amp;nbsp; NumDays.&amp;nbsp; &amp;nbsp;SumofDesats.&amp;nbsp; &amp;nbsp; AvgDesats&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I included my code to start and the question related to what i have to do so it makes it easier. Please help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you guys so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 03:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665230#M198869</guid>
      <dc:creator>mthomas2014</dc:creator>
      <dc:date>2020-06-26T03:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665233#M198871</link>
      <description>Could you please post the sample data that is there in DesatsLong.sas7bdat for one or subject so that we can use it to write the code</description>
      <pubDate>Fri, 26 Jun 2020 03:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665233#M198871</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-26T03:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665240#M198876</link>
      <description>&lt;P&gt;Here is the data too. sorry I forgot to include.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Michael&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 04:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665240#M198876</guid>
      <dc:creator>mthomas2014</dc:creator>
      <dc:date>2020-06-26T04:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665247#M198879</link>
      <description>&lt;P&gt;1) Assuming weeks start the same date for all IDs then it is possible to create a format&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; that defines the week number per date, from the earliest to the last one.&lt;/P&gt;
&lt;P&gt;2) Please post a sample data using code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines;
   input ID DAY ....;
datalines;
1  &amp;lt;day or date&amp;gt; ...
2  ..............
; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you post the PROC CONTENTS output, it may be helpful too.&lt;/P&gt;
&lt;P&gt;3) Use PROC MEANS to calculate the sum and the average per DAY assigned the new format,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; i.e. per ID and week, creating&amp;nbsp; output dataset - one observation per ID per week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having a sample data enables us to post you the full code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 05:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665247#M198879</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-26T05:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665249#M198880</link>
      <description>&lt;P&gt;So you need to summarize per week, where "week" is defined not from a date value, but a day number.&lt;/P&gt;
&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    id,
    int(day/7) + 1 as week,
    sum(desats) as sum_desats,
    avg(desats) as avg_desats
  from desats
  group by id, calculated week
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested, posted from my tablet)&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 06:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665249#M198880</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-26T06:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665250#M198881</link>
      <description>&lt;P&gt;In case DAY contains a date then you can use next code.&lt;/P&gt;
&lt;P&gt;I have created a dummy test data-set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
     do ID = 1 to 5;
	    do DAY = '01JAN2020'd to '28FEB2020'd;
		   destas = 100*ranuni(0);
		   output;
		 end;
	end;
	format destas 5.2;
run;

proc sql noprint;
   select min(DAY), max(DAY) into :DayStart, :DayEnd 
     from test;
quit;
%put DayStart=&amp;amp;daystart  DayEnd = &amp;amp;dayend;

data cntl;
     retain fmtname 'week';
     do date = &amp;amp;DayStart to &amp;amp;DayEnd;
        week = int((date - &amp;amp;dayStart)/7 +1);
        end = date;
        label = put(week,2.);
        output;
     end;
     rename date = start;
run;
proc format lib=work cntlin=cntl; run;

proc means data=test nway noprint;
  class ID DAY;
  var destas;
  output out=want(rename=(_freq_ = DAYS) drop=_type_)
         sum=SumDestas  mean=AvgDestas;
  format day week. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2020 06:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665250#M198881</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-26T06:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665263#M198886</link>
      <description>&lt;P&gt;Please try the below code,&lt;/P&gt;
&lt;P&gt;1) create a dummy dataset considering you have per id 12 weeks of data. in this dummy dataset you will have week and day variables.&lt;/P&gt;
&lt;P&gt;2) merge the dummy dataset with the original dataset on day variable. this way each id will get the week information from dummy dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) then derive the numdays, SumofDesats and AvgDesats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data dummy;
do week= 1 to 12;
do i = 1 to 7;
day+1;
output;
end;
end;
run;

proc sort data=dummy;
by day ;
run;

data want;
merge have(in=a) dummy(in=b);
by day;
if a;
run;

proc sort data=want;
by id week;
run;

data want2;
set want;
by id week;
retain numdays SumofDesats;
if first.week then numdays=1;
else numdays+1; 
if first.week then SumofDesats=NumDesat;
else SumofDesats+NumDesat;

if last.week;
 AvgDesats=SumofDesats/numdays;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 809px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46683i78063EECC407455F/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 07:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665263#M198886</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-26T07:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need help on where to even start please</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665275#M198892</link>
      <description>&lt;P&gt;I figured it out. you guys are awesome thank you so much for the help. I cant thank you both enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Glad to be a part of the SAS community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 08:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-on-where-to-even-start-please/m-p/665275#M198892</guid>
      <dc:creator>mthomas2014</dc:creator>
      <dc:date>2020-06-26T08:22:18Z</dc:date>
    </item>
  </channel>
</rss>

