<?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 Add column to multiple table based on specific criteria in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140218#M37477</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following tables :&lt;/P&gt;&lt;P&gt;KPI.ACTION_LOG&lt;/P&gt;&lt;P&gt;KPI.CREATE_ALERT&lt;/P&gt;&lt;P&gt;KPI.CREATE_CASE&lt;/P&gt;&lt;P&gt;KPI.ACTION_TAKEN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each of those table contains a timestamp. This variable is either called CREATION_TIMESTAMP or LOGTIMESTAMP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to create a SAS procedures that would loop through each of those tables and create several columns based on the logic given below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the following logic, I use the MAX() &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;function&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;in order to get my year or month based on the logtimestamp or the creation_timestamp, since if the value is missing the other variable will be kept. &lt;/SPAN&gt;I'm pretty sure this is not the right way to do it. I also have no idea how to loop through the 4 tables mentioned above in order to add the different columns to each of them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My logic :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WORK.extract_final;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set KPI.ACTION_LOG;&lt;/P&gt;&lt;P&gt;&amp;nbsp; YEAR = MAX(YEAR(DATEPART(LOGTIMESTAMP)),YEAR(DATEPART(CREATION_TIMESTAMP)));&lt;/P&gt;&lt;P&gt;&amp;nbsp; MONTH = MAX(MONTH(DATEPART(LOGTIMESTAMP)),MONTH(DATEPART(CREATION_TIMESTAMP)));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 11 then do; mois_compt = 1; trim_compt= 'Q1'; annee_compt = year+1; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 12 then do; mois_compt = 2; trim_compt= 'Q1'; annee_compt = year+1; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 1 then do; mois_compt = 3; trim_compt= 'Q1'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 2 then do; mois_compt = 4; trim_compt= 'Q2'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 3 then do; mois_compt = 5; trim_compt= 'Q2'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 4 then do; mois_compt = 6; trim_compt= 'Q2'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 5 then do; mois_compt = 7; trim_compt= 'Q3'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 6 then do; mois_compt = 8; trim_compt= 'Q3'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 7 then do; mois_compt = 9; trim_compt= 'Q3'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 8 then do; mois_compt = 10; trim_compt= 'Q4'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 9 then do; mois_compt = 11; trim_compt= 'Q4'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 10 then do; mois_compt = 12; trim_compt= 'Q4'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quarter = catx('-',annee_compt,trim_compt);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope you understand what I am trying to accomplish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Mar 2014 22:06:21 GMT</pubDate>
    <dc:creator>nicnad</dc:creator>
    <dc:date>2014-03-11T22:06:21Z</dc:date>
    <item>
      <title>Add column to multiple table based on specific criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140218#M37477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following tables :&lt;/P&gt;&lt;P&gt;KPI.ACTION_LOG&lt;/P&gt;&lt;P&gt;KPI.CREATE_ALERT&lt;/P&gt;&lt;P&gt;KPI.CREATE_CASE&lt;/P&gt;&lt;P&gt;KPI.ACTION_TAKEN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each of those table contains a timestamp. This variable is either called CREATION_TIMESTAMP or LOGTIMESTAMP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to create a SAS procedures that would loop through each of those tables and create several columns based on the logic given below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the following logic, I use the MAX() &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;function&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;in order to get my year or month based on the logtimestamp or the creation_timestamp, since if the value is missing the other variable will be kept. &lt;/SPAN&gt;I'm pretty sure this is not the right way to do it. I also have no idea how to loop through the 4 tables mentioned above in order to add the different columns to each of them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My logic :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WORK.extract_final;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set KPI.ACTION_LOG;&lt;/P&gt;&lt;P&gt;&amp;nbsp; YEAR = MAX(YEAR(DATEPART(LOGTIMESTAMP)),YEAR(DATEPART(CREATION_TIMESTAMP)));&lt;/P&gt;&lt;P&gt;&amp;nbsp; MONTH = MAX(MONTH(DATEPART(LOGTIMESTAMP)),MONTH(DATEPART(CREATION_TIMESTAMP)));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 11 then do; mois_compt = 1; trim_compt= 'Q1'; annee_compt = year+1; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 12 then do; mois_compt = 2; trim_compt= 'Q1'; annee_compt = year+1; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 1 then do; mois_compt = 3; trim_compt= 'Q1'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 2 then do; mois_compt = 4; trim_compt= 'Q2'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 3 then do; mois_compt = 5; trim_compt= 'Q2'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 4 then do; mois_compt = 6; trim_compt= 'Q2'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 5 then do; mois_compt = 7; trim_compt= 'Q3'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 6 then do; mois_compt = 8; trim_compt= 'Q3'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 7 then do; mois_compt = 9; trim_compt= 'Q3'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 8 then do; mois_compt = 10; trim_compt= 'Q4'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 9 then do; mois_compt = 11; trim_compt= 'Q4'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if month = 10 then do; mois_compt = 12; trim_compt= 'Q4'; annee_compt = year; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; quarter = catx('-',annee_compt,trim_compt);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope you understand what I am trying to accomplish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Mar 2014 22:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140218#M37477</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2014-03-11T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add column to multiple table based on specific criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140219#M37478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use intnx and formats to do this rather than multiple lines of code.&lt;/P&gt;&lt;P&gt;date_max=datepart(max(dt1, dt2));&lt;/P&gt;&lt;P&gt;new_date=intnx('month', date_max, 2);&lt;/P&gt;&lt;P&gt;mois_compt=month(new_date);&lt;/P&gt;&lt;P&gt;quarter=put(mois_compt, yyqd7.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A starting point at least. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Mar 2014 22:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140219#M37478</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-03-11T22:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Add column to multiple table based on specific criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140220#M37479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think you code achieve what I want to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In fact when month() of a timestamp = 11, I want mois_compt to equal 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if you need further explanations&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 18:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140220#M37479</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2014-03-12T18:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Add column to multiple table based on specific criteria</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140221#M37480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're incrementing it by 2 months, which is why the intnx function increments the date by 2 months.&lt;/P&gt;&lt;P&gt;Have you tried it and it doesn't work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 18:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-column-to-multiple-table-based-on-specific-criteria/m-p/140221#M37480</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-03-12T18:22:31Z</dc:date>
    </item>
  </channel>
</rss>

