<?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 do I sort a data set by 2 specific criterias in 2 seperate variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501313#M481</link>
    <description>&lt;P&gt;The original excel file is formatted with the dates as follows:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2017-04-15 1:30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2017-04-15 2:50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Once I imported them into a sas data set they look like this:&lt;BR /&gt;15APR17:00:01:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I used what you suggested and for all three the error message i'm receiving is the following:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;831 where start_position=6008 and variable_2=:'30APR17';&lt;BR /&gt;ERROR: WHERE clause operator requires compatible variables.&lt;BR /&gt;832 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 02:05:51 GMT</pubDate>
    <dc:creator>doofst</dc:creator>
    <dc:date>2018-10-04T02:05:51Z</dc:date>
    <item>
      <title>how do I sort a data set by 2 specific criterias in 2 seperate variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501306#M477</link>
      <description>&lt;P&gt;I have created a sas data named tables.Q3 from an excel file containing hundreds of thousands of observations.&lt;/P&gt;&lt;P&gt;I would like to now extract specific observations that satisfy one condition in 1 variable and another condition in&amp;nbsp;the other and print those data sets.&lt;/P&gt;&lt;P&gt;I first sorted the data set by one variable using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SORT DATA=tables.Q3 OUT=tables.Q4;&lt;BR /&gt;BY&amp;nbsp;start_position;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;this produced a sas data set that sorted the start_code (which is a numeric) variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to now&amp;nbsp;print from the dataset tables.Q4 a table that will only include those observations that satisfy start_position=5000 and variable 2&amp;nbsp;(which is a datetime variable in the form of DDMMMYYY HH:MM:SS) as one specific date (i.e 20OCT17).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help.&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>Thu, 04 Oct 2018 01:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501306#M477</guid>
      <dc:creator>doofst</dc:creator>
      <dc:date>2018-10-04T01:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort a data set by 2 specific criterias in 2 seperate variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501309#M478</link>
      <description>&lt;P&gt;The right statement depends on whether VARIABLE_2 is truly a SAS datetime value, or whether it is a character string.&amp;nbsp; Either set of conditions is easy, and you can test easily enough which of these will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=q4;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;* For true datetimes:&amp;nbsp; &amp;nbsp;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;where start_position=5000 and datepart(variable_2) = '20oct2017'd;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#00FF00"&gt;* For character strings that contain a two-digit year:&amp;nbsp; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#00FF00"&gt;where start_position=5000 and variable_2 =: '20OCT17';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800000"&gt;* For character strings that contain a four-digit year:&amp;nbsp; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800000"&gt;where start_position=5000 and variable_2 =: '20OCT2017';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 01:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501309#M478</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-04T01:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort a data set by 2 specific criterias in 2 seperate variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501313#M481</link>
      <description>&lt;P&gt;The original excel file is formatted with the dates as follows:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2017-04-15 1:30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2017-04-15 2:50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Once I imported them into a sas data set they look like this:&lt;BR /&gt;15APR17:00:01:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I used what you suggested and for all three the error message i'm receiving is the following:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;831 where start_position=6008 and variable_2=:'30APR17';&lt;BR /&gt;ERROR: WHERE clause operator requires compatible variables.&lt;BR /&gt;832 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 02:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501313#M481</guid>
      <dc:creator>doofst</dc:creator>
      <dc:date>2018-10-04T02:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort a data set by 2 specific criterias in 2 seperate variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501450#M518</link>
      <description>&lt;P&gt;You'll have to find out a little more about the data then.&amp;nbsp; After importing the data to SAS, run a PROC CONTENTS on the SAS data set and look at the characteristics of VARIABLE_2.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 12:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501450#M518</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-04T12:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: how do I sort a data set by 2 specific criterias in 2 seperate variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501569#M537</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238105"&gt;@doofst&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have created a sas data named tables.Q3 from an excel file containing hundreds of thousands of observations.&lt;/P&gt;
&lt;P&gt;I would like to now extract specific observations that satisfy one condition in 1 variable and another condition in&amp;nbsp;the other and print those data sets.&lt;/P&gt;
&lt;P&gt;I first sorted the data set by one variable using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=tables.Q3 OUT=tables.Q4;&lt;BR /&gt;BY&amp;nbsp;start_position;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;this produced a sas data set that sorted the start_code (which is a numeric) variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to now&amp;nbsp;print from the dataset tables.Q4 a table that will only include those observations that satisfy start_position=5000 and variable 2&amp;nbsp;(which is a datetime variable in the form of DDMMMYYY HH:MM:SS) as one specific date (i.e 20OCT17).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for the help.&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are selecting by the datetime? or just want to display the datetime as a date in that format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare the code snippet you say generated an error:&lt;/P&gt;
&lt;PRE&gt;831 where start_position=6008 and variable_2=:'30APR17';
ERROR: WHERE clause operator requires compatible variables.
832 run;&lt;/PRE&gt;
&lt;P&gt;with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s suggestion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;where start_position=5000 and &lt;STRONG&gt;&lt;FONT color="#339966"&gt;datepart&lt;/FONT&gt;&lt;/STRONG&gt;(variable_2) = '20oct2017'&lt;STRONG&gt;&lt;FONT color="#339966"&gt;d&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/PRE&gt;
&lt;P&gt;DATE literals are quoted values ind date7 or date9 appearance followed by a D to tell SAS this intended to be used as a date literal. Without the D it is treated a simple character value and generates the error comparing numeric to character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function DATEPART tells SAS to only use the Date portion of a datetime value. The =: is right out as you want the date literal numeric version.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-do-I-sort-a-data-set-by-2-specific-criterias-in-2-seperate/m-p/501569#M537</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-04T16:21:44Z</dc:date>
    </item>
  </channel>
</rss>

