<?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: RE: Data Selection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235867#M268196</link>
    <description>&lt;P&gt;Thanks PG.....That worked perfectly!!!....&lt;/P&gt;</description>
    <pubDate>Sat, 21 Nov 2015 20:53:45 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2015-11-21T20:53:45Z</dc:date>
    <item>
      <title>RE: Data Selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235862#M268192</link>
      <description>&lt;P&gt;Hi....I am trying to select data records from a dataset based on the ID and this ID is selected under 2 conditions. Those 2 conditions are if the date is before 20150908, then I only want to select those ID's where the Surcharge is less than 10% of the Cost. Similiarly, for the second condition, if the date is after 20150908, then I only want to select those ID's where the Surcharge is less than %% of the Cost. My question is can I combine these 2 conditions under the same PROC SQL, like have below or should or need to run to PROC SQL and combine the results together after?.....Thanks in advance.&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;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CREATE TABLE Want AS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT A.*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM WORK.Summary A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LEFT JOIN&amp;nbsp;(SELECT DISTINCT ID&lt;/P&gt;
&lt;P&gt;FROM WORK.Summary&lt;/P&gt;
&lt;P&gt;(WHERE NUM=’P585’&lt;/P&gt;
&lt;P&gt;AND SIN=’02234566’&lt;/P&gt;
&lt;P&gt;AND DATE &amp;lt; ‘20150908’&lt;/P&gt;
&lt;P&gt;HAVING SURCHARGE &amp;lt; 0.1*COST&lt;/P&gt;
&lt;P&gt;ORDER BY ID)&lt;/P&gt;
&lt;P&gt;AND&lt;/P&gt;
&lt;P&gt;(WHERE NUM=’P585’&lt;/P&gt;
&lt;P&gt;AND SIN=’02234566’&lt;/P&gt;
&lt;P&gt;AND DATE &amp;gt;= ‘20150908’&lt;/P&gt;
&lt;P&gt;HAVING SURCHARGE &amp;lt; 0.05*COST&lt;/P&gt;
&lt;P&gt;ORDER BY ID)) B&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON A.ID=B.ID;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 19:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235862#M268192</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2015-11-21T19:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: RE: Data Selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235864#M268193</link>
      <description>&lt;P&gt;Although not syntaxically correct, your SQL query seems to be equivalent to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE Want AS
SELECT *
FROM Summary
WHERE 
	NUM=’P585’ AND 
	SIN=’02234566’ AND 
	(	DATE &amp;lt;  '08SEP2015'd AND SURCHARGE &amp;lt; 0.10*COST OR
		DATE &amp;gt;= '08SEP2015'd AND SURCHARGE &amp;lt; 0.05*COST );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;that is, assuming your dates are real dates and not character strings. If your dates are indeed character strings, you could get away with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE Want AS
SELECT *
FROM Summary
WHERE 
	NUM=’P585’ AND 
	SIN=’02234566’ AND 
	(	DATE &amp;lt;  '20150908' AND SURCHARGE &amp;lt; 0.10*COST OR
		DATE &amp;gt;= '20150908' AND SURCHARGE &amp;lt; 0.05*COST );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Nov 2015 20:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235864#M268193</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-21T20:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: RE: Data Selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235865#M268194</link>
      <description>&lt;P&gt;Hi PG....thank you for your response. I am not too sure if I would get the complete data from your suggestion. The reason I have to select distinct ID's first is that I only want data based on when the Surcharge is less that a certain percent of the cost which changed on a certain date (20150908) for this particular Num and SIN. Once I have a list of distinct ID's based on these condition, I need to go back to the same dataset and extract a complete dataset&amp;nbsp;for only&amp;nbsp;these ID's as they will have other records with different SIN. So really I want to end up with a complete dataset for all the records in the dataset for only these distinct ID's if the 2 conditions are met. Hopefully this clarifies&amp;nbsp;things....Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 20:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235865#M268194</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2015-11-21T20:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: RE: Data Selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235866#M268195</link>
      <description>&lt;P&gt;OK, then what you need is something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE Want AS
SELECT *
FROM Summary
WHERE ID IN
( 	SELECT ID
	FROM Summary
	WHERE 
		NUM=’P585’ AND 
		SIN=’02234566’ AND 
		(	DATE &amp;lt;  '08SEP2015'd AND SURCHARGE &amp;lt; 0.10*COST OR
			DATE &amp;gt;= '08SEP2015'd AND SURCHARGE &amp;lt; 0.05*COST ) );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;or the equivalent if dates are character strings.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 20:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235866#M268195</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-21T20:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: RE: Data Selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235867#M268196</link>
      <description>&lt;P&gt;Thanks PG.....That worked perfectly!!!....&lt;/P&gt;</description>
      <pubDate>Sat, 21 Nov 2015 20:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-Data-Selection/m-p/235867#M268196</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2015-11-21T20:53:45Z</dc:date>
    </item>
  </channel>
</rss>

