<?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 to check if a variable not exists in a dataset first then proc sql insert into table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394492#M95075</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/128890"&gt;@JHE&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Something like below could do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
  origin='Master';
  format myDateVar date9.;

  myDateVar='01Aug2017'd;
  do i=1 to 10;
    output;
  end;
run;

data trans;
  format myDateVar date9.;
  origin='Trans';

  i=11;
  myDateVar='05Aug2017'd;
  output;

  i=12;
  myDateVar='01Sep2017'd;
  origin='Trans';
  output;
run;

%let max_month='01Jan1960'd;
proc sql noprint;
  select name into:varlist separated by ','
  from dictionary.columns where libname='WORK' and memname='MASTER' order by varnum
  ;
  select max(intnx('month',myDateVar,0,'b')) into :max_month
  from master
  ;
  insert into master
  select &amp;amp;varlist
  from trans
  where intnx('month',myDateVar,0,'b') &amp;gt; &amp;amp;max_month
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 10 Sep 2017 06:53:18 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-09-10T06:53:18Z</dc:date>
    <item>
      <title>how to check if a variable not exists in a dataset first then proc sql insert into table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394488#M95072</link>
      <description>&lt;P&gt;I want check wheather exsiting in the dataset, then preform PROC&amp;nbsp;SQL insert into table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example check if&amp;nbsp;month 2017-08 not exsiting then&lt;/P&gt;&lt;P&gt;&amp;nbsp;Proc SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Insert into table ...&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2017 04:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394488#M95072</guid>
      <dc:creator>JHE</dc:creator>
      <dc:date>2017-09-10T04:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a variable not exists in a dataset first then proc sql insert into table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394490#M95073</link>
      <description>&lt;P&gt;Are you trying to check for a value in a column, if it doesn't exist insert a new row with the value?&lt;/P&gt;
&lt;P&gt;Or are you trying to create a new variable?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If its the first look af an UPDATE statement instead.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2017 05:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394490#M95073</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-10T05:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a variable not exists in a dataset first then proc sql insert into table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394492#M95075</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/128890"&gt;@JHE&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Something like below could do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master;
  origin='Master';
  format myDateVar date9.;

  myDateVar='01Aug2017'd;
  do i=1 to 10;
    output;
  end;
run;

data trans;
  format myDateVar date9.;
  origin='Trans';

  i=11;
  myDateVar='05Aug2017'd;
  output;

  i=12;
  myDateVar='01Sep2017'd;
  origin='Trans';
  output;
run;

%let max_month='01Jan1960'd;
proc sql noprint;
  select name into:varlist separated by ','
  from dictionary.columns where libname='WORK' and memname='MASTER' order by varnum
  ;
  select max(intnx('month',myDateVar,0,'b')) into :max_month
  from master
  ;
  insert into master
  select &amp;amp;varlist
  from trans
  where intnx('month',myDateVar,0,'b') &amp;gt; &amp;amp;max_month
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Sep 2017 06:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394492#M95075</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-10T06:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a variable not exists in a dataset first then proc sql insert into table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394514#M95080</link>
      <description>&lt;P&gt;Thank you, that works.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Sep 2017 15:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-variable-not-exists-in-a-dataset-first-then/m-p/394514#M95080</guid>
      <dc:creator>JHE</dc:creator>
      <dc:date>2017-09-10T15:08:59Z</dc:date>
    </item>
  </channel>
</rss>

