<?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: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538546#M6965</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222221"&gt;@moseland&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am learning SAS with the SAS essentials learning module that has been very helpful thus far. One of the practice questions requries we produce the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=pg1.storm_summary out=STORM_SORT;&lt;BR /&gt;where Basin IN ("NA" "na");&lt;BR /&gt;by descending MaxWindMPH;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand that the above code is creating an output file called STORM_SORT that has certain filters. Based ont he log I got ~400 rows returned.&amp;nbsp; I'm trying to dig deeper with my understanding and tried a PROC PRINT step&amp;nbsp; that tries to print the same filtered information as before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc print data=pg1.storm_summary;&lt;BR /&gt;where Basin IN ("NA" "na");&lt;BR /&gt;by descending MaxWindMPH;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run it only 1 row is returned. I am stumped as to what my error is. Please help point me in the right direction and thank you!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Read your log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm expecting to see an error regarding the BY statement, since it's not sorted you cannot use that as the BY statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Feb 2019 03:03:28 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-26T03:03:28Z</dc:date>
    <item>
      <title>Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538544#M6964</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am learning SAS with the SAS essentials learning module that has been very helpful thus far. One of the practice questions requries we produce the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=pg1.storm_summary out=STORM_SORT;&lt;BR /&gt;where Basin IN ("NA" "na");&lt;BR /&gt;by descending MaxWindMPH;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that the above code is creating an output file called STORM_SORT that has certain filters. Based ont he log I got ~400 rows returned.&amp;nbsp; I'm trying to dig deeper with my understanding and tried a PROC PRINT step&amp;nbsp; that tries to print the same filtered information as before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc print data=pg1.storm_summary;&lt;BR /&gt;where Basin IN ("NA" "na");&lt;BR /&gt;by descending MaxWindMPH;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run it only 1 row is returned. I am stumped as to what my error is. Please help point me in the right direction and thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 02:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538544#M6964</guid>
      <dc:creator>moseland</dc:creator>
      <dc:date>2019-02-26T02:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538546#M6965</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222221"&gt;@moseland&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am learning SAS with the SAS essentials learning module that has been very helpful thus far. One of the practice questions requries we produce the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=pg1.storm_summary out=STORM_SORT;&lt;BR /&gt;where Basin IN ("NA" "na");&lt;BR /&gt;by descending MaxWindMPH;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand that the above code is creating an output file called STORM_SORT that has certain filters. Based ont he log I got ~400 rows returned.&amp;nbsp; I'm trying to dig deeper with my understanding and tried a PROC PRINT step&amp;nbsp; that tries to print the same filtered information as before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc print data=pg1.storm_summary;&lt;BR /&gt;where Basin IN ("NA" "na");&lt;BR /&gt;by descending MaxWindMPH;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run it only 1 row is returned. I am stumped as to what my error is. Please help point me in the right direction and thank you!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Read your log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm expecting to see an error regarding the BY statement, since it's not sorted you cannot use that as the BY statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 03:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538546#M6965</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-26T03:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538552#M6967</link>
      <description>&lt;P&gt;You were right! When i check the log I get the following explanation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data set PG1.STORM_SUMMARY is not sorted in descending sequence. The current BY group has MaxWindMPH = ' 35'&lt;BR /&gt;and the next BY group has MaxWindMPH = ' 190'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I don't understand is the variable MaxWindMPH has many other values other than 35 and 190. Would I need to sort the entire data set by descending order first&amp;nbsp; and then sort again by the variable I want, MaxWindMPH?&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, 26 Feb 2019 04:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538552#M6967</guid>
      <dc:creator>moseland</dc:creator>
      <dc:date>2019-02-26T04:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538560#M6968</link>
      <description>&lt;P&gt;Change your PROC PRINT step to use the sorted dataset, rather than your unsorted one, and it will work perfectly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc print data=storm_sort;
where Basin IN ("NA" "na");
by descending MaxWindMPH;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 05:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538560#M6968</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-02-26T05:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538589#M6972</link>
      <description>&lt;P&gt;You need to look at what the procedure in question is doing, and what it is for.&lt;/P&gt;
&lt;P&gt;Proc sort - this procedure is for sorting data.&lt;/P&gt;
&lt;P&gt;Proc print - this procedure is for printing data.&lt;/P&gt;
&lt;P&gt;You do not use proc print to sort, hence when you use the by statement in a proc print, it assumes the data is already sorted, and as it is not then your procedure fails.&lt;/P&gt;
&lt;P&gt;Unlike SQL (and other languages) data going into procedures is expected to be sorted when using by group processing, if it isn't then you will get warnings/errors.&amp;nbsp; If you add the option notsorted, then you will get output, but it will block the data in the order it finds it, which is often not the way intended, so use cautiously.&lt;/P&gt;
&lt;P&gt;So, if your problem is, I want to sort the data, then print it out:&lt;BR /&gt;1) proc sort out=sorted&lt;/P&gt;
&lt;P&gt;2) proc print data=sorted&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 08:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538589#M6972</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-26T08:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538703#M6983</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222221"&gt;@moseland&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You were right! When i check the log I get the following explanation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set PG1.STORM_SUMMARY is not sorted in descending sequence. The current BY group has MaxWindMPH = ' 35'&lt;BR /&gt;and the next BY group has MaxWindMPH = ' 190'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I don't understand is the variable MaxWindMPH has many other values other than 35 and 190. Would I need to sort the entire data set by descending order first&amp;nbsp; and then sort again by the variable I want, MaxWindMPH?&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, once it's sorted it's fine, even if filtered because the sort order will still be correct, assuming you use a data step. If you're using SQL there is no guarantee of order.&lt;STRONG&gt; But your PROC PRINT is referencing the original unsorted data set, not your sorted data set&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/538703#M6983</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-26T16:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort Followed by PROC PRINT, confusion on why I am not getting uniform results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/539946#M7153</link>
      <description>&lt;P&gt;This concept now makes sense. Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2019 22:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-Sort-Followed-by-PROC-PRINT-confusion-on-why-I-am-not/m-p/539946#M7153</guid>
      <dc:creator>moseland</dc:creator>
      <dc:date>2019-03-03T22:36:24Z</dc:date>
    </item>
  </channel>
</rss>

