<?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: Create rolling 12 months of datasets from large dataset contain 15 months of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769395#M244042</link>
    <description>&lt;P&gt;So you want to create 12 individual datasets - one for each of the preceding months, correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, there are better ways to do this.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Sep 2021 16:54:45 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-09-22T16:54:45Z</dc:date>
    <item>
      <title>Create rolling 12 months of datasets from large dataset contain 15 months of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769384#M244038</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a macro that creates 15 datasets by date from one dataset that contains 15 months of data indexed by datekey in the format yyyymmdd.&amp;nbsp; It is a simple set statement with a where clause. Because I'm rewriting this code from someone else, there are already 15 individual datasets in mylib.&amp;nbsp; I only want 12 rolling months of datasets.&amp;nbsp; In the code I've attached, I created all 15 datasets again because I thought that would be easiest.&amp;nbsp; What I'd really like going forward is to read 12 months of data from the large dataset (which I can by adjusting _N_) and delete the earliest mylib dataset that's already out there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*date_key is in format yyyymmdd.*/
proc sql;
create table testdata as
select distinct date_key from mylib.mth_datasets;
quit;
/*the most recent date will be id 1*/
proc sort data=testdata out=unique nodupkey;
	by descending date_key:
run;
data unique;
	set unique;
	id=_N_;
data _null_;
	set unique end=last;
	if last then call symput('N', put(id, 3.));
%let i = 1
%macro getdata (dsn);
%do i = 1 %to &amp;amp;N;
data _null_;
	set unique;
	call symputx(cats("date_nbr"),put(intnx('month',today(),-&amp;amp;i,'E'), yyyymmdd.));
run;
data mylib.mth_datasets_&amp;amp;date_key;
	set &amp;amp;dsn;
	where date_key = &amp;amp;date_nbr;
%end;
%mend getdata;
%getdata(mylib.mth_datasets)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Sep 2021 04:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769384#M244038</guid>
      <dc:creator>dkcoop</dc:creator>
      <dc:date>2021-09-23T04:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create rolling 12 months of datasets from large dataset contain 15 months of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769395#M244042</link>
      <description>&lt;P&gt;So you want to create 12 individual datasets - one for each of the preceding months, correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, there are better ways to do this.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 16:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769395#M244042</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-09-22T16:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create rolling 12 months of datasets from large dataset contain 15 months of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769765#M244109</link>
      <description>&lt;P&gt;I'm sure there ARE better ways of doing this than what I am doing.&amp;nbsp; While searching for solutions I've managed to patch together a program that does what I want but if there's a better way I'd love to know it!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 01:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769765#M244109</guid>
      <dc:creator>dkcoop</dc:creator>
      <dc:date>2021-09-23T01:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create rolling 12 months of datasets from large dataset contain 15 months of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769790#M244115</link>
      <description>&lt;P&gt;I inserted your code into a code box for better readability.&lt;/P&gt;
&lt;P&gt;This&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data unique;
	set unique;
	id=_N_;
data _null_;
	set unique end=last;
	if last then call symput('N', put(id, 3.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can be easier done by retrieving the number of obs from DICTIONARY.TABLES:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nobs into :n from dictionary.tables
where libname = "WORK" and memname = "UNIQUE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To use a last date to create a cutoff from a large dataset, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select intnx('month',max(date_key),-12,'b') into : cutoff
from mylib.mth_datasets;
quit;

data want;
set mylib.mth_datasets;
where date_key ge &amp;amp;cutoff.;
/* other code */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Big business-class hint: make it a habit to always end your steps with a RUN statement. Sooner or later an "open" step will cause havoc with the timing of global or macro statements.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 05:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769790#M244115</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-23T05:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create rolling 12 months of datasets from large dataset contain 15 months of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769956#M244205</link>
      <description>&lt;P&gt;I tried&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;select intnx('month',max(date_key),-12,'b') into : cutoff&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But am getting Note "invalid arguument to function intnx missing values may be generated and nothing is returned.&amp;nbsp; Is it the max function?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 15:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769956#M244205</guid>
      <dc:creator>dkcoop</dc:creator>
      <dc:date>2021-09-23T15:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create rolling 12 months of datasets from large dataset contain 15 months of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769971#M244214</link>
      <description>&lt;P&gt;I am, of course, assuming that your date_key variable contains valid SAS dates, which means it is numeric and has a YYMMDDN8. format attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With SAS dates, the code works, see here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date_key yymmdd10.;
format date_key yymmdd10.;
datalines;
2021-09-20
2021-08-31
;

proc sql noprint;
select intnx('month',max(date_key),-12,'b') into : cutoff
from have;
quit;

data _null_;
cutoff = &amp;amp;cutoff;
put cutoff yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log excerpt:&lt;/P&gt;
&lt;PRE&gt; 82         data _null_;
 83         cutoff = &amp;amp;cutoff;
 84         put cutoff yymmdd10.;
 85         run;
 
 2020-09-01
&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Sep 2021 16:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-rolling-12-months-of-datasets-from-large-dataset-contain/m-p/769971#M244214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-23T16:56:32Z</dc:date>
    </item>
  </channel>
</rss>

