<?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: How do I determine monthly to quarterly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393758#M94853</link>
    <description>%macro case_months;&lt;BR /&gt;%do mo=1 %to 12;&lt;BR /&gt;%if %eval(&amp;amp;mo&amp;lt;10) %then %do;&lt;BR /&gt;data case_0&amp;amp;mo.2017;&lt;BR /&gt;case_mo=&amp;amp;mo.;&lt;BR /&gt;case_yr=2017;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%if %eval(&amp;amp;mo&amp;gt;=10) %then %do;&lt;BR /&gt;data case_&amp;amp;mo.2017;&lt;BR /&gt;case_mo=&amp;amp;mo.;&lt;BR /&gt;case_yr=2017;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%case_months;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;create table case_table_list as&lt;BR /&gt;select memname,mdy(input(substr(scan(memname,2,"_"),1,2),8.),1,input(substr(scan(memname,2,"_"),3,4),8.) ) as date format=date9.,&lt;BR /&gt;qtr(calculated date) as qtr&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname='WORK' and MEMNAME like 'CASE_%';&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro Combine_By_Qtr(qtr);&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select memname into: memname separated by ' ' from case_table_list where qtr=&amp;amp;qtr. ;&lt;BR /&gt;quit;&lt;BR /&gt;%if %eval(&amp;amp;sqlobs&amp;gt;0) %then %do;&lt;BR /&gt;data qtr_&amp;amp;qtr;&lt;BR /&gt;set &amp;amp;memname.;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%Combine_By_Qtr(1);&lt;BR /&gt;%Combine_By_Qtr(2);&lt;BR /&gt;%Combine_By_Qtr(3);&lt;BR /&gt;%Combine_By_Qtr(4);&lt;BR /&gt;</description>
    <pubDate>Thu, 07 Sep 2017 04:49:26 GMT</pubDate>
    <dc:creator>ShiroAmada</dc:creator>
    <dc:date>2017-09-07T04:49:26Z</dc:date>
    <item>
      <title>How do I determine monthly to quarterly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393751#M94850</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have monthly datasets as per below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Case_072017&lt;/P&gt;
&lt;P&gt;Case_082017&lt;/P&gt;
&lt;P&gt;Case_092017&lt;/P&gt;
&lt;P&gt;Case_102017&lt;/P&gt;
&lt;P&gt;Case_112017&lt;/P&gt;
&lt;P&gt;Case_122017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I convert monthly datasets name to determine that dataset falls into which quarter?&lt;/P&gt;
&lt;P&gt;Is it scan function? Or I can use macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expectation is I want to gather monthly&amp;nbsp;datasets and group it under each quarter. This program will be running the next month of each quarter. For example for 4th quarter, the program will be executed on 4th of January.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 03:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393751#M94850</guid>
      <dc:creator>Hhh111</dc:creator>
      <dc:date>2017-09-07T03:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine monthly to quarterly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393754#M94851</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have saved all my dataset in one library and then using sashelp.vstable I am able to find dataset name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using dataset name, I try to find out the month and year.&lt;/P&gt;
&lt;P&gt;Finaly I create a macro variable qtr_dsn that would store all the dataset name for quarter=3 and year =2017.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname month "/folders/myfolders";
data month.Case_072017;
dt='01Jul2017'd;
run;

data month.Case_082017;
dt='01Aug2017'd;
run;

data month.Case_092017;
dt='01Sep2017'd;
run;


proc sql;
create table dataset_nm
as select memname
from sashelp.vstable
where libname='MONTH';
quit;

DATA TEMP;
SET dataset_nm;
month=input(SUBSTR(memname,6,2),8.);
year=input(SUBSTR(memname,8,4),8.);
if month in (1,2,3) then qtr =1;
if month in (4,5,6) then qtr =2;
if month in (7,8,9) then qtr =3;
if month in (10,11,12) then qtr =4;
RUN;

proc sql; 
select memname into :qtr_dsn separated by " "
from temp
where qtr=3 and year =2017;
quit;
%put &amp;amp;qtr_dsn;

data dsn_qtr3;
set &amp;amp;qtr_dsn;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 04:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393754#M94851</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2017-09-07T04:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine monthly to quarterly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393758#M94853</link>
      <description>%macro case_months;&lt;BR /&gt;%do mo=1 %to 12;&lt;BR /&gt;%if %eval(&amp;amp;mo&amp;lt;10) %then %do;&lt;BR /&gt;data case_0&amp;amp;mo.2017;&lt;BR /&gt;case_mo=&amp;amp;mo.;&lt;BR /&gt;case_yr=2017;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%if %eval(&amp;amp;mo&amp;gt;=10) %then %do;&lt;BR /&gt;data case_&amp;amp;mo.2017;&lt;BR /&gt;case_mo=&amp;amp;mo.;&lt;BR /&gt;case_yr=2017;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%case_months;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;create table case_table_list as&lt;BR /&gt;select memname,mdy(input(substr(scan(memname,2,"_"),1,2),8.),1,input(substr(scan(memname,2,"_"),3,4),8.) ) as date format=date9.,&lt;BR /&gt;qtr(calculated date) as qtr&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname='WORK' and MEMNAME like 'CASE_%';&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro Combine_By_Qtr(qtr);&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select memname into: memname separated by ' ' from case_table_list where qtr=&amp;amp;qtr. ;&lt;BR /&gt;quit;&lt;BR /&gt;%if %eval(&amp;amp;sqlobs&amp;gt;0) %then %do;&lt;BR /&gt;data qtr_&amp;amp;qtr;&lt;BR /&gt;set &amp;amp;memname.;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%Combine_By_Qtr(1);&lt;BR /&gt;%Combine_By_Qtr(2);&lt;BR /&gt;%Combine_By_Qtr(3);&lt;BR /&gt;%Combine_By_Qtr(4);&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2017 04:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393758#M94853</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-07T04:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine monthly to quarterly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393786#M94863</link>
      <description>&lt;P&gt;Please explain the expected result. Do you want to append the monthly datasets creating a new dataset? Or, do you want to rename the monthly datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code creates one dataset per quarter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   create view work.datasets as
      select catx('.', LibName, MemName) as Dataset, 
            input(cats('01', substr(MemName, 6)), ddmmyy8.) as quarter format=yyq.
         from sashelp.vtable
            where libname = 'WORK' and MemName like 'CASE%2017'
         order by quarter;
   ;
quit;

data work.NewNames;
   set work.Datasets;
   by quarter;

   length DatasetList $ 200;

   if first.Quarter then DatasetList = '';

   DatasetList = catx(' ', DatasetList, Dataset);

   if last.Quarter then do;
      call execute(catx(' ', 'data', cats('case_', vvalue(Quarter)), '; set', DatasetList, '; run;'));
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 08:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/393786#M94863</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-09-07T08:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I determine monthly to quarterly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/395433#M95373</link>
      <description>&lt;P&gt;TQ for the helppp!!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 08:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-determine-monthly-to-quarterly/m-p/395433#M95373</guid>
      <dc:creator>Hhh111</dc:creator>
      <dc:date>2017-09-13T08:58:41Z</dc:date>
    </item>
  </channel>
</rss>

