<?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: Getting past weeks data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845060#M36768</link>
    <description>&lt;P&gt;So really, you want to get the last 7 obs of your data, correct?&lt;/P&gt;</description>
    <pubDate>Fri, 18 Nov 2022 08:31:09 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-11-18T08:31:09Z</dc:date>
    <item>
      <title>Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844803#M36724</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I need a small help from you all. I've a table with a date variable in that I wanna get past week's data. I used a condition called where=(date= today() -7) but the thing here is&amp;nbsp;&lt;SPAN&gt;for that date variable it has no weekends and Mondays in it. Please help me out to get the past 7 days data irrespective of date values in it. Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844803#M36724</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-17T12:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844808#M36727</link>
      <description>&lt;P&gt;You say you want the past weeks data. But really, you want data from the &lt;U&gt;&lt;EM&gt;latest 7 dates&lt;/EM&gt;&lt;/U&gt; in your data, correct?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844808#M36727</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T12:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844811#M36729</link>
      <description>&lt;P&gt;Correct!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844811#M36729</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-17T12:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844817#M36732</link>
      <description>&lt;P&gt;Here's an approach. See if you can use that as a template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data = sashelp.stocks out = rank ties = dense descending;
   var date;
   ranks r;
run;

data want;
   set rank;
   where r &amp;lt;= 7;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844817#M36732</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T12:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844818#M36733</link>
      <description>&lt;P&gt;Appreciate it. Can't it be possible to keep a condition in the input table in a data step?.&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;Set have (condition);&lt;/P&gt;&lt;P&gt;Somewhat like that?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844818#M36733</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-17T12:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844822#M36735</link>
      <description>&lt;P&gt;No. Not directly. You would have to do some pre-processing of your data. Otherwise, how would you know the 7'th largest date in your data?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844822#M36735</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T12:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844824#M36737</link>
      <description>&lt;P&gt;7th largest?. What I meant was I require a condition to get the past 7 days data irrespective of dates in my table. And FYI, they don't have weekends and Mondays .&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844824#M36737</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-17T12:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844828#M36738</link>
      <description>&lt;P&gt;Same thing. SAS Dates are integers. If you want to retrieve data for the latest 7 days of your data, you would have to know the 7'th largest value of date and retrieve everything above that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 13:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844828#M36738</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T13:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844902#M36744</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420851"&gt;@Vasundha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I need a small help from you all. I've a table with a date variable in that I wanna get past week's data. I used a condition called where=(date= today() -7) but the thing here is&amp;nbsp;&lt;SPAN&gt;for that date variable it has no weekends and Mondays in it. Please help me out to get the past 7 days data irrespective of date values in it. Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That code wouldn't work because you are using =, so it only finds one date.&lt;/P&gt;
&lt;P&gt;Did you try&lt;/P&gt;
&lt;PRE&gt; where=( date ge ( today() -7 ) )&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 15:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/844902#M36744</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-17T15:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845053#M36762</link>
      <description>&lt;P&gt;Thanks for replying me, I've tried your code it gives me just 3 dates cuz when we're using today () -7 function in that condition it is counting weekends, Mondays as well. That's why I got only 3 dates as output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Explanation : today () -7&amp;nbsp;&lt;/P&gt;&lt;P&gt;17Nov22&lt;/P&gt;&lt;P&gt;16Nov22&lt;/P&gt;&lt;P&gt;15Nov22&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Alongside these 3 dates I must also get 11Nov22, 10Nov22, 09Nov22 &amp;amp; 08Nov22.&lt;/P&gt;&lt;P&gt;Note: like I mentioned earlier I've no weekends and Mondays in my data for some reason.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 07:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845053#M36762</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-18T07:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845054#M36763</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420851"&gt;@Vasundha&lt;/a&gt;&amp;nbsp;, did you try the approach that I posted above? If it does not suit you and you have not yet found your answer, I encourage you to post some sample data for us to work with that resembles your actual data and your desired result. Makes it much easier to provide a usable code answer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 07:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845054#M36763</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-18T07:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845055#M36764</link>
      <description>&lt;P&gt;Brute force approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=have (keep=date)
  out=dates
  nodupkey
;
by descending date;
run;

data _null_;
set dates point=7;
call symputx("cutoff",date);
stop;
run;

data want;
set have;
where date ge &amp;amp;cutoff.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the PROC RANK method is more efficient.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 07:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845055#M36764</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-18T07:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845056#M36765</link>
      <description>&lt;P&gt;Sure, here's my data.&lt;/P&gt;&lt;PRE&gt;Data have;
Input in_date : date9. readings;
format in_date date9.;
Datalines;
18NOV2022 10
17NOV2022 12
16NOV2022 15
15NOV2022 45
11NOV2022 67
10NOV2022 60
09NOV2022 61
08Nov2022 89
04Nov2022 40
;
run;
Note: I require a condition in the input table to get the  past 7 days data i.e&lt;/PRE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420851"&gt;@Vasundha&lt;/a&gt;&amp;nbsp;, did you try the approach that I posted above? If it does not suit you and you have not yet found your answer, I encourage you to post some sample data for us to work with that resembles your actual data and your desired result. Makes it much easier to provide a usable code answer.&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE&gt;A condition like this : &lt;BR /&gt;Data want;&lt;BR /&gt;Set have(condition);&lt;BR /&gt;run;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt; &lt;BR /&gt;

18Nov2022 10
17Nov2022 12
16Nov2022 15
15Nov2022 45
11Nov2022 67
10Nov2022 60
09Nov2022 61&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845056#M36765</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-18T08:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845057#M36766</link>
      <description>&lt;P&gt;Is this data representative? Do you have only 1 obs per date? Is the data sorted descending by date?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845057#M36766</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-18T08:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845058#M36767</link>
      <description>&lt;P&gt;Yes, I've only one obs per date and they're in ascending order in my table. My bad I gave you data in descending order. Please Nevermind.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Is this data representative? Do you have only 1 obs per date? Is the data sorted descending by date?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845058#M36767</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-18T08:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845060#M36768</link>
      <description>&lt;P&gt;So really, you want to get the last 7 obs of your data, correct?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845060#M36768</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-18T08:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845061#M36769</link>
      <description>&lt;P&gt;If so, then try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input in_date : date9. readings;
format in_date date9.;
Datalines;
04Nov2022 40
08Nov2022 89
09NOV2022 61
10NOV2022 60
11NOV2022 67
15NOV2022 45
16NOV2022 15
17NOV2022 12
18NOV2022 10
;
run;

data want;
  do p = max(1, n - 6) to n;
    set have nobs = n point = p;
    output;
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845061#M36769</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-18T08:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845063#M36770</link>
      <description>&lt;P&gt;Right&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845063#M36770</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-18T08:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845064#M36771</link>
      <description>&lt;P&gt;I really appreciate your efforts however I was wondering that can't it be possible in input table in a data step?.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845064#M36771</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-11-18T08:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting past weeks data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845065#M36772</link>
      <description>&lt;P&gt;To&amp;nbsp;&lt;EM&gt;evaluate&lt;/EM&gt; data with SAS, it must first be brought into SAS. First import, then use one of the methods suggested, then subset.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 08:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Getting-past-weeks-data/m-p/845065#M36772</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-18T08:50:32Z</dc:date>
    </item>
  </channel>
</rss>

