<?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: SET two datasets conditionally using where in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573516#M161925</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't know why but it shows the following errors...maybe because I used macro variables here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data perm;&lt;/P&gt;&lt;P&gt;271 set perm (where =( month_end_date ge &amp;amp;mfend.d and month_end_date ne &amp;amp;mthend.d))&lt;/P&gt;&lt;P&gt;271 set perm (where =( month_end_date ge &amp;amp;mfend.d and month_end_date ne &amp;amp;mthend.d))&lt;/P&gt;&lt;P&gt;___&lt;/P&gt;&lt;P&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jul 2019 14:34:33 GMT</pubDate>
    <dc:creator>ForrestYao</dc:creator>
    <dc:date>2019-07-15T14:34:33Z</dc:date>
    <item>
      <title>SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573506#M161918</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to merge two datasets conditionally using SET and WHERE statements, I am not sure if the syntax is valid.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data perm;&lt;/P&gt;&lt;P&gt;SET A (where&amp;nbsp;= (month_end_date ge '2016-12-01' and month_end_date ne '2018-12-01'))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know if there are other ways to&amp;nbsp;obtain&amp;nbsp;the same output (I know MERGE may work, but anything except that)?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 14:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573506#M161918</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-07-15T14:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573508#M161919</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264359"&gt;@ForrestYao&lt;/a&gt;&amp;nbsp;Almost correct. You missed a d after quotation for dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data perm;

SET A (where = (month_end_date ge '2016-12-01'd and month_end_date ne '2018-12-01'd))

        B;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Should work unless I underestimated your requirement.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 14:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573508#M161919</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-07-15T14:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573509#M161920</link>
      <description>&lt;P&gt;You will need to provide more information/explanation of what you are trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you posted will take a subset of the observations from A and append all of the observations from B.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 14:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573509#M161920</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-15T14:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573513#M161922</link>
      <description>&lt;P&gt;Basically, I would like to select all the historical data and append the most recent month data to it.&lt;/P&gt;&lt;P&gt;A is all historical data, B is the most recent data.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 14:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573513#M161922</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-07-15T14:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573516#M161925</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't know why but it shows the following errors...maybe because I used macro variables here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data perm;&lt;/P&gt;&lt;P&gt;271 set perm (where =( month_end_date ge &amp;amp;mfend.d and month_end_date ne &amp;amp;mthend.d))&lt;/P&gt;&lt;P&gt;271 set perm (where =( month_end_date ge &amp;amp;mfend.d and month_end_date ne &amp;amp;mthend.d))&lt;/P&gt;&lt;P&gt;___&lt;/P&gt;&lt;P&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 14:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573516#M161925</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-07-15T14:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573517#M161926</link>
      <description>To see what the error is flagging you need to see what code it is actually seeing.  So show the values of the macro variables.&lt;BR /&gt;If they have actual date value (either a raw integer or a date literal) then there is no need for the D suffix.  If they just have strings that look like dates (without quotes) such as 10JAN2019 then you need to add the quotes so that SAS sees a validly formatted date literal.&lt;BR /&gt;</description>
      <pubDate>Mon, 15 Jul 2019 14:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573517#M161926</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-15T14:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573534#M161939</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264359"&gt;@ForrestYao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't know why but it shows the following errors...maybe because I used macro variables here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data perm;&lt;/P&gt;
&lt;P&gt;271 set perm (where =( month_end_date ge &amp;amp;mfend.d and month_end_date ne &amp;amp;mthend.d))&lt;/P&gt;
&lt;P&gt;271 set perm (where =( month_end_date ge &amp;amp;mfend.d and month_end_date ne &amp;amp;mthend.d))&lt;/P&gt;
&lt;P&gt;___&lt;/P&gt;
&lt;P&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;B&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say that you are lucky this did not work. Was your intent to remove all of the historical data in your PERM set except those dates?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have actual SAS dates in your MONTH_END_DATE variable and your macro variable looks anything like the example in your question of '2016-12-01'&amp;nbsp;then as minimum you code basically won't work as the value '2016-12-01'D will not be treated as a date by SAS. The only literal values are the ddMONyy or ddMONyyyy, "01DEC2016"d for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code without the macro values is pretty useless as a LOT of stuff can be stuck into a single macro variable (MVARSIZE the default value for the number of characters in a single macro variable is 65534)&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573534#M161939</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-15T15:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573535#M161940</link>
      <description>&lt;P&gt;I assume that you want to append Data set A to Data set B. Both data sets are assumed to have same variables. In this case, you can use Proc Append which will simply append A to B without reading B which means less I/O times. Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data A;
   set sashelp.class (where = (age =14));
run;

data B;
   set sashelp.class (where = (age ^=14));
run;

proc append base = B data = A;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573535#M161940</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-07-15T15:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573536#M161941</link>
      <description>&lt;P&gt;Thanks, I will try that&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573536#M161941</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-07-15T15:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573538#M161942</link>
      <description>&lt;P&gt;Thank you, I got what you mean, I intend to append the most recent month data into the historical month data where I only keep certain period of historical data.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 15:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573538#M161942</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-07-15T15:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573616#M161988</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264359"&gt;@ForrestYao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, I got what you mean, I intend to append the most recent month data into the historical month data where I only keep certain period of historical data.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It may not hurt to provide some detail about the month_end_date&amp;nbsp;variable such as type (numeric or character) and format. If the variable is not numeric&amp;nbsp;then almost any range comparison, such as GE,&amp;nbsp;can yield unexpected results.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2019 17:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573616#M161988</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-15T17:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: SET two datasets conditionally using where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573736#M162027</link>
      <description>&lt;P&gt;The syntax of your dates is wrong.&lt;/P&gt;
&lt;P&gt;This works to shed old data and add new data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PERM;
  set PERM  (where = (MONTH_END_DATE &amp;gt;= '01JAN2016'd ))
      NEW;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Don't forget to set the correct metadata for this permanent table (mainly: sorted order, indexes, compression, password protection) depending on your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last step for the creation of permanent tables should be something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=READY 
          out =PERMANENT( compress=..  index=... alter=.. write=.. as needed ) 
          presorted ; 
  by MONTH_END_DATE; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This makes your data safer from accidental erasure, and speeds up it use.&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 03:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-two-datasets-conditionally-using-where/m-p/573736#M162027</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-07-16T03:30:16Z</dc:date>
    </item>
  </channel>
</rss>

