<?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: Running an IF Else with a value from a table to execute another proc sql in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704268#M37817</link>
    <description>&lt;P&gt;OMG that worked.&amp;nbsp; Thank thank you!!!&amp;nbsp; I just reversed the macro to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &amp;amp;snapshot_date = &amp;amp;rundate-1 %then %do;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Dec 2020 19:59:57 GMT</pubDate>
    <dc:creator>cyberjunkie</dc:creator>
    <dc:date>2020-12-07T19:59:57Z</dc:date>
    <item>
      <title>Running an IF Else with a value from a table to execute another proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704236#M37812</link>
      <description>&lt;P&gt;Trying to figure out what the proper code to execute an if else from SAS EG with a value from a table.&amp;nbsp; If you see below I've commented out the sas date value and I want to replace it with a select statement from a table.&amp;nbsp; Basically I just want the execute to run when the today value -1 = the value in the table I created prior based on SASDate.&amp;nbsp; I've tried creating a query from the snapshot_date table and using the select sql syntax and replacing the value but it keeps giving me an&amp;nbsp;ERROR 388-185: Expecting an arithmetic operator.&amp;nbsp;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE SNAPSHOT_DATE AS&lt;BR /&gt;SELECT PUT(DATEPART(MAX(AUDIT_BATCH_TS))-1,yymmddd10.) as 'Snapshot Date'n,&lt;BR /&gt;today() as RunDate,&lt;BR /&gt;DATEPART(MAX(AUDIT_BATCH_TS))-1 as SASDate FROM Ora_PSA.CC_ACTIVITY;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if (today()) =/*22256*/ then call execute(&lt;/P&gt;&lt;P&gt;"PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE DIM_ASSIGNQUEUE AS&lt;BR /&gt;SELECT DISTINCT Q1.ID as 'QUEUEID'n,&lt;BR /&gt;Q1.NAME as 'Queue Name'n,&lt;BR /&gt;Q1.DESCRIPTION as 'Queue Description'n,&lt;BR /&gt;GROUPID FROM Ora_PSA.CC_ASSIGNQUEUE Q1 INNER JOIN (SELECT ID, MAX(AUDIT_BATCH_TS) AS MAXTS FROM Ora_PSA.CC_ASSIGNQUEUE GROUP BY ID) MAXQ ON MAXQ.ID = Q1.ID AND MAXQ.MAXTS = Q1.AUDIT_BATCH_TS;&lt;/P&gt;&lt;P&gt;QUIT;"&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 18:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704236#M37812</guid>
      <dc:creator>cyberjunkie</dc:creator>
      <dc:date>2020-12-07T18:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Running an IF Else with a value from a table to execute another proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704245#M37813</link>
      <description>&lt;P&gt;I cannot picture what you want to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post example data from both tables? Please post as simple data steps to recreate the data.&lt;/P&gt;
&lt;P&gt;For your posted input data show what code you want to run and what output it should produce.&amp;nbsp;&amp;nbsp;Please show clearly what part of the code you want to run with these selected value(s) depends on (or changes) based on that value was selected from the other table.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 18:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704245#M37813</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-07T18:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Running an IF Else with a value from a table to execute another proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704252#M37814</link>
      <description>&lt;P&gt;Basically I want to be able to use the value from this table attached to populate the highlighted text in RED below.&amp;nbsp; I'd like a dynamic value based on the results of my first PROC SQL query to drive the next step.&amp;nbsp; If the snapshot date matches then it will continue to create the next table, otherwise it will not.&amp;nbsp; Hope that explains what I'm trying to do.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if (today()) =&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&lt;U&gt;22256&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;then call execute(&lt;/P&gt;&lt;P&gt;"PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE DIM_ASSIGNQUEUE AS&lt;BR /&gt;SELECT DISTINCT Q1.ID as 'QUEUEID'n,&lt;BR /&gt;Q1.NAME as 'Queue Name'n,&lt;BR /&gt;Q1.DESCRIPTION as 'Queue Description'n,&lt;BR /&gt;GROUPID FROM Ora_PSA.CC_ASSIGNQUEUE Q1 INNER JOIN (SELECT ID, MAX(AUDIT_BATCH_TS) AS MAXTS FROM Ora_PSA.CC_ASSIGNQUEUE GROUP BY ID) MAXQ ON MAXQ.ID = Q1.ID AND MAXQ.MAXTS = Q1.AUDIT_BATCH_TS;&lt;/P&gt;&lt;P&gt;QUIT;"&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 19:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704252#M37814</guid>
      <dc:creator>cyberjunkie</dc:creator>
      <dc:date>2020-12-07T19:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Running an IF Else with a value from a table to execute another proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704255#M37815</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="snapshot_example.jpg" style="width: 317px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52418iF0BA6DF20BBE1CBC/image-size/large?v=v2&amp;amp;px=999" role="button" title="snapshot_example.jpg" alt="snapshot_example.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 19:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704255#M37815</guid>
      <dc:creator>cyberjunkie</dc:creator>
      <dc:date>2020-12-07T19:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Running an IF Else with a value from a table to execute another proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704262#M37816</link>
      <description>&lt;P&gt;So to get the MAX() date from your first query use code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
SELECT DATEPART(MAX(AUDIT_BATCH_TS))-1, today()
  into :snapshot_date trimmed, :rundate trimmed
  from Ora_PSA.CC_ACTIVITY
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will create two macro variables with raw SAS date values.&lt;/P&gt;
&lt;P&gt;Then to conditionally run the other step you could use %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;rundate = &amp;amp;snapshot_date %then %do;
PROC SQL;
CREATE TABLE DIM_ASSIGNQUEUE AS
  SELECT DISTINCT Q1.ID as 'QUEUEID'n
       , Q1.NAME as 'Queue Name'n
       , Q1.DESCRIPTION as 'Queue Description'n
       , GROUPID 
  FROM Ora_PSA.CC_ASSIGNQUEUE Q1
  INNER JOIN 
    (SELECT ID, MAX(AUDIT_BATCH_TS) AS MAXTS 
     FROM Ora_PSA.CC_ASSIGNQUEUE 
     GROUP BY ID
    ) MAXQ
  ON MAXQ.ID = Q1.ID AND MAXQ.MAXTS = Q1.AUDIT_BATCH_TS
;
QUIT;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are using an old version of SAS where the open code %IF/%THEN/%DO is not allowed then you could use your data step instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;run_date= &amp;amp;snapshot_date then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure why you are making variable names with spaces in them.&amp;nbsp; It is much easier to program if the names follow normal conventions.&amp;nbsp; You can always attach labels to the variables if you want your reports to default to nice text for headers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 19:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704262#M37816</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-07T19:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Running an IF Else with a value from a table to execute another proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704268#M37817</link>
      <description>&lt;P&gt;OMG that worked.&amp;nbsp; Thank thank you!!!&amp;nbsp; I just reversed the macro to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &amp;amp;snapshot_date = &amp;amp;rundate-1 %then %do;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 19:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Running-an-IF-Else-with-a-value-from-a-table-to-execute-another/m-p/704268#M37817</guid>
      <dc:creator>cyberjunkie</dc:creator>
      <dc:date>2020-12-07T19:59:57Z</dc:date>
    </item>
  </channel>
</rss>

