<?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 macro variable is in a column,if it's not, insert rows from/into a different tab in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336772#M63033</link>
    <description>&lt;P&gt;1. Sample data?&lt;/P&gt;
&lt;P&gt;2. Are your dates character fields or SAS dates (numeric with a date format). This defines how the comparison will have to work, though you could get around it easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is untested but the sketch of the idea of how this could works. There are multiple ways to do each step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_whatever(month_p);

%*check if value exists in table;

proc sql noprint;
select month_name into :var_check
from tableA
where month_name = "&amp;amp;month_p";
quit;

%if &amp;amp;var_check  ne %str() %then %do;

proc append data=tableB base=TableA;
run;

%end;

%mend;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2017 22:46:00 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-02-28T22:46:00Z</dc:date>
    <item>
      <title>how to check if macro variable is in a column,if it's not, insert rows from/into a different table?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336765#M63030</link>
      <description>&lt;P&gt;I have&lt;/P&gt;&lt;P&gt;-table A with a single column with month values like: "jan2016", "feb2017", "aug2014"...&lt;/P&gt;&lt;P&gt;-table B with the columns: month, name, like: "jan2016", "john smith"...&lt;/P&gt;&lt;P&gt;-table C with the same columns as table B&lt;/P&gt;&lt;P&gt;-a macro variable with a month value stored in it, like ""jan2016"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. check whether the value stored in the macro variable is in table A&lt;/P&gt;&lt;P&gt;2. if it is, terminate program, if it is not then&lt;/P&gt;&lt;P&gt;3. insert all the rows in table B into table C?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would prefer to do this with Proc SQL, although data steps are ok too if the result is the same as SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: adding sample data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tableA;&lt;BR /&gt;input month $;&lt;BR /&gt;datalines;&lt;BR /&gt;jan2016&lt;BR /&gt;feb2017&lt;BR /&gt;aug2014&lt;BR /&gt;dec2010&lt;BR /&gt;jan2013&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data tableB;&lt;BR /&gt;input month $ name $;&lt;BR /&gt;datalines;&lt;BR /&gt;apr2000 john_smith&lt;BR /&gt;apr2000 karl&lt;BR /&gt;apr2000 lidia&lt;BR /&gt;apr2000 anna&lt;BR /&gt;apr2000 francis&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data tableC;&lt;BR /&gt;input month $ name $;&lt;BR /&gt;datalines;&lt;/P&gt;&lt;P&gt;nov2001 amelie&lt;BR /&gt;nov2001 juan&lt;BR /&gt;nov2001 joe&lt;BR /&gt;nov2001 norman&lt;BR /&gt;nov2001 katie&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;%let month=nov2001;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 23:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336765#M63030</guid>
      <dc:creator>Datino</dc:creator>
      <dc:date>2017-02-28T23:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if macro variable is in a column,if it's not, insert rows from/into a different tab</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336769#M63032</link>
      <description>Can you provide some sample data to work with?</description>
      <pubDate>Tue, 28 Feb 2017 22:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336769#M63032</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-28T22:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if macro variable is in a column,if it's not, insert rows from/into a different tab</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336772#M63033</link>
      <description>&lt;P&gt;1. Sample data?&lt;/P&gt;
&lt;P&gt;2. Are your dates character fields or SAS dates (numeric with a date format). This defines how the comparison will have to work, though you could get around it easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is untested but the sketch of the idea of how this could works. There are multiple ways to do each step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_whatever(month_p);

%*check if value exists in table;

proc sql noprint;
select month_name into :var_check
from tableA
where month_name = "&amp;amp;month_p";
quit;

%if &amp;amp;var_check  ne %str() %then %do;

proc append data=tableB base=TableA;
run;

%end;

%mend;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 22:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/336772#M63033</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-28T22:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if macro variable is in a column,if it's not, insert rows from/into a different tab</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/337170#M63057</link>
      <description>&lt;P&gt;For some reason, Reeza's code worked some times and threw errors others. I got the following code to run, it's probably not the best solution, but it works.&lt;/P&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;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table work.recs_to_add as&lt;BR /&gt;select *&lt;BR /&gt;from&lt;BR /&gt;tableB&lt;BR /&gt;where&lt;BR /&gt;not exists (select * from tableC where month="&amp;amp;month");&lt;BR /&gt;insert into tableC&lt;BR /&gt;select * from work.recs_to_add;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 22:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-check-if-macro-variable-is-in-a-column-if-it-s-not-insert/m-p/337170#M63057</guid>
      <dc:creator>Datino</dc:creator>
      <dc:date>2017-03-01T22:52:00Z</dc:date>
    </item>
  </channel>
</rss>

