<?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: By Variables Not Properly Sorted in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307469#M65855</link>
    <description>&lt;P&gt;Your final BY statement includes CLIENT_SPECIALTY_FLAG.&amp;nbsp; But that variable was assigned a value in the DATA step.&amp;nbsp; Why would you expect the data to be in order by this newly created variable?&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2016 19:21:42 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-10-26T19:21:42Z</dc:date>
    <item>
      <title>By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307463#M65851</link>
      <description>&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = work.Calculated_Data2;
  by AffiliationID ApprovedPriceType BRAND_GENERIC CarrierID ClaimOriginationFlag 
     ClaimStatus CLIENT CostTypeCode DISPENSEASWRITTENDAWPRODUCTSELE 
     ExtendedSupplyNetworkIndicator FilledMonth FilledQuarter FinalPlanCode GPINumber 
     MailOrderIndicator MultiSourceCode PlanDrugStatus PriceScheduleDefinition RxNetworkID 
     SERVICEPROVIDERID SuperPharmacyNetworkID PHARMACYZIPCODE Specialty_Flag EXCLUSIONS 
     IVLIndicator;
run; 

data Calculated_Data3;
  format Discount_HCSC Discount_AL Discount_FL Discount_Medd
         Discount_MN Discount_NC Discount_Prime Discount_Horizon Percent8.4;
  length Client_Specialty_Flag $30;
  if _N_ = 1 then do;
    declare Hash S (dataset:"egtask.SPECIALTY_LIST");
	  S.definekey("ProductServiceID");
	  S.definedata("Discount_HCSC");
	  S.definedata("Discount_AL");
	  S.definedata("Discount_FL");
	  S.definedata("Discount_MEDD");
	  S.definedata("Discount_MN");
	  S.definedata("Discount_NC");
	  S.definedata("Discount_Prime");
	  S.definedata("Discount_Horizon");
	  S.definedone();
	end;
  set Calculated_Data2;
  if S.find() = 0 then do;
    Discount_HCSC=Discount_HCSC;
    Discount_AL=Discount_AL;
    Discount_FL=Discount_FL;
    Discount_Horizon=Discount_Horizon;
    Discount_Prime=Discount_Prime;
    Discount_MN=Discount_MN;
    Discount_NC=Discount_NC;
    Discount_MEDD=Discount_MEDD;
  end;
  if CLIENT in("IL","NM","OK","TX","MT","NM") and Discount_HCSC ne . then Client_Specialty_Flag = "Specialty";
  else if CLIENT in("KS","ND","NE","WY") and Discount_Prime ne . then Client_Specialty_Flag = "Specialty";
  else if CLIENT = "MN" and Discount_MN ne . then Client_Specialty_Flag = "Specialty";
  else if CLIENT = "AL" and Discount_AL ne . then Client_Specialty_Flag = "Specialty";
  else if CLIENT = "FL" and Discount_FL ne . then Client_Specialty_Flag = "Specialty";
  else if CLIENT = "NJ" and Discount_Horizon ne . then Client_Specialty_Flag = "Specialty";
  else if CLIENT = "NC" and Discount_NC ne . then Client_Specialty_Flag = "Specialty";
  else Client_Specialty_Flag = "Non-Specialty";
run;

data EGTASK.Data_Put_In_Access;
  set work.Calculated_Data3;
  format AffiliationID $6. ApprovedPriceType $10. CarrierID $9. ClaimOriginationFlag $1.
		 ClaimStatus $1. CostTypeCode $10. DISPENSEASWRITTENDAWPRODUCTSELE $1.
		 ExtendedSupplyNetworkIndicator $1. FilledMonth $7. FilledQuarter $6.
		 GPINumber $14. MailOrderIndicator $1. MultiSourceCode $1. PlanDrugStatus $1.
		 PriceScheduleDefinition $10. RxNetworkID $6. RxNetworkID_CHAIN $6.
         SERVICEPROVIDERID $15. SuperPharmacyNetworkID $6. PHARMACYZIPCODE $10.
		 SUM_of_ApprovedIngredientCost DOLLAR16.2 SUM_of_ApprDispFeeAmount DOLLAR16.2 SUM_of_QUANTITYDISPENSED 13.3 ZIP $10.;
  RxNetworkID_CHAIN = RxNetworkID;
  SUM_of_ApprovedIngredientCost = sum(ApprovedIngredientCost);
  SUM_of_ApprDispFeeAmount = sum(ApprovedDispensingFeeAmount);
  SUM_of_AWP = sum(AWP);
  SUM_of_RX = sum(RX);
  SUM_of_QUANTITYDISPENSED = sum(QUANTITYDISPENSED);
  SUM_of_MEMBERID = sum(MemberID);
  ZIP = PHARMACYZIPCODE;
  by AffiliationID ApprovedPriceType BRAND_GENERIC CarrierID ClaimOriginationFlag 
     ClaimStatus CLIENT CostTypeCode DISPENSEASWRITTENDAWPRODUCTSELE 
     ExtendedSupplyNetworkIndicator FilledMonth FilledQuarter FinalPlanCode GPINumber 
     MailOrderIndicator MultiSourceCode PlanDrugStatus PriceScheduleDefinition RxNetworkID 
     SERVICEPROVIDERID SuperPharmacyNetworkID PHARMACYZIPCODE Specialty_Flag Client_Specialty_Flag EXCLUSIONS 
     IVLIndicator;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error occurs when I get to the last datastep (in the by). It give me the error: "Variables are not properly sorted in dataset WORK.Calculated_Data3". The weird thing is, earlier on in the project, Calculated_Data2 is created with a subsetting condition based on a range of dates. When I run it for one month, it runs through this code and works with no errors. But when I run it for 4 months, it throws the error. What could be going on here?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307463#M65851</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-10-26T18:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307466#M65853</link>
      <description>&lt;P&gt;Depending on SAS instalation and SAS system options, in case of multi-threading (parallel computing)&lt;/P&gt;
&lt;P&gt;output of a datastep (your data2) may&amp;nbsp;be not sorted. In such case you need to sort it again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As much as I know there is an option to keep output sorted. Need search for appropriate option.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 19:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307466#M65853</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-26T19:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307469#M65855</link>
      <description>&lt;P&gt;Your final BY statement includes CLIENT_SPECIALTY_FLAG.&amp;nbsp; But that variable was assigned a value in the DATA step.&amp;nbsp; Why would you expect the data to be in order by this newly created variable?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 19:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307469#M65855</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-26T19:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307471#M65857</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;Right, but when I create Calculated_Data2 in a previous step in the project, I subset by a range of dates. When I run that with a date period of one month, everything sorts fine and produces correct results with no errors, but when I run it for multiple months, I suddenly get sort error.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 19:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307471#M65857</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-10-26T19:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307480#M65862</link>
      <description>&lt;P&gt;It's got to be data-related.&amp;nbsp; Unfortunately, I can't really examine your data.&amp;nbsp; But something along these lines:&amp;nbsp; perhaps for a single month, CLIENT_SPECIALTY_FLAG is always "Non-Specialty".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 20:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307480#M65862</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-26T20:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307481#M65863</link>
      <description>&lt;P&gt;you entered the&amp;nbsp;&lt;STRONG&gt;Client_Specialty_Flag &lt;/STRONG&gt;on&lt;STRONG&gt; BY &lt;/STRONG&gt;statement before&amp;nbsp;&lt;STRONG&gt;IVLIndicator&amp;nbsp;&lt;/STRONG&gt;(the minor BY variables);&lt;/P&gt;
&lt;P&gt;In case of changing flag value the order is spoiled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 20:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307481#M65863</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-26T20:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307492#M65869</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel﻿&lt;/a&gt;&amp;nbsp;Could you explain further I'm not sure I understand...&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 21:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307492#M65869</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-10-26T21:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307519#M65879</link>
      <description>&lt;P&gt;Let's say the by statment was: &lt;STRONG&gt;BY X &amp;nbsp;Z &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;where X Z are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 2&lt;/P&gt;
&lt;P&gt;You add a new variable Y and change to &lt;STRONG&gt;BY X Y Z&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;so data is now:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X Y Z&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 B 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 A 2&lt;/P&gt;
&lt;P&gt;then data is not sorted by X Y Z.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 23:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307519#M65879</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-26T23:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307673#M65927</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel﻿&lt;/a&gt;&amp;nbsp;Okay, I see what's you're saying. But it should have failed then for the smaller dataset. I should have gotten the same error... It can't be just a matter of size. Am I right? As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;suggested, it may be because Client_Specialty_Flag has only one value in the smaller data set. But I looked and it has two values: "Non-Specialty" and "Specialty".&amp;nbsp;Also, I think I may be misunderstanding what the by statement in the data step is supposed to do. I'm under the impression that it simply orders by those variables. Is this correct?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 15:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307673#M65927</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-10-27T15:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307692#M65932</link>
      <description>&lt;P&gt;You have much to learn, young Jedi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The BY statement does not order the observations.&amp;nbsp; Rather, it is permitted when the observations are already in order.&amp;nbsp; Its purpose is to set up flags that inform you when a group of observations (same values for all of the BY variables) begins or ends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The are plenty of details.&amp;nbsp; What are the names of these flags?&amp;nbsp; What values are they assigned?&amp;nbsp; How can you do this if your data is grouped, but not sorted?&amp;nbsp; It's a very important topic, worth the time to study.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 16:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307692#M65932</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-27T16:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307697#M65933</link>
      <description>&lt;P&gt;&amp;nbsp;When you run PROC SORT data=...; &lt;STRONG&gt;BY&lt;/STRONG&gt;&amp;nbsp;&amp;lt;list of keys&amp;gt;;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;you define how to sort/order the data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, when you use &amp;nbsp;Data out; Set input; &lt;STRONG&gt;BY&lt;/STRONG&gt; &amp;lt;list of keys&amp;gt;; ... ( or other proc with BY )&lt;/P&gt;
&lt;P&gt;you declare that the program may assume that data is already sorted by those keys,&lt;/P&gt;
&lt;P&gt;in the order of variables&amp;nbsp;given in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need data to be sorted in order to calculate data per group.&lt;/P&gt;
&lt;P&gt;The group is defined by the whole list (e.g. &lt;STRONG&gt;BY&lt;/STRONG&gt; a b c d ) &amp;nbsp;or by part of it (like: &lt;STRONG&gt;BY&lt;/STRONG&gt; a b only).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you deal with small dataset, probably the&amp;nbsp;keys were in right order;&lt;/P&gt;
&lt;P&gt;As you increase in data the probability to "break" the order is raising.&lt;/P&gt;
&lt;P&gt;You can use &lt;STRONG&gt;OPTIONS OBS= n;&amp;nbsp;&lt;/STRONG&gt; to deal with different number of observations&lt;/P&gt;
&lt;P&gt;(e.g: try 1000, if ok try again by 2000 else try by 500, etc. and then look at the dataset keys to identify where&lt;/P&gt;
&lt;P&gt;&amp;nbsp;the order is broken);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in yout specific case "Non-Specialty" should preceed "Specialty" as "N" comes &lt;STRONG&gt;before&lt;/STRONG&gt; "S" in alphabetic order.&lt;/P&gt;
&lt;P&gt;if you find any&amp;nbsp;&lt;SPAN&gt;"Non-Specialty" comming &lt;STRONG&gt;after&lt;/STRONG&gt;&amp;nbsp;"Specialty", this is a broken order point.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I hope I clarified the double meaning of &lt;STRONG&gt;BY&lt;/STRONG&gt; statemnet. (I know that my english is not the best);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 17:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307697#M65933</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-27T17:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307716#M65940</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel﻿&lt;/a&gt;&amp;nbsp;Okay I think I for the most part understand by group processing now. What I still don't understand is when you said &amp;nbsp;&lt;/P&gt;&lt;P&gt;"When you deal with small dataset, probably the&amp;nbsp;keys were in right order;&amp;nbsp;As you increase in data the probability to "break" the order is raising." I'm confused as to why a greater number of observations may cause the order to break. I don't see why the keys would be in a different order just because you added more data to the dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 18:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307716#M65940</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-10-27T18:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307738#M65949</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;Okay I think I for the most part understand by group processing now. What I still don't understand is when you said &amp;nbsp;&lt;/P&gt;
&lt;P&gt;"When you deal with small dataset, probably the&amp;nbsp;keys were in right order;&amp;nbsp;As you increase in data the probability to "break" the order is raising." I'm confused as to why a greater number of observations may cause the order to break. I don't see why the keys would be in a different order just because you added more data to the dataset.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have a data set that you sort by 15 different variables but do not have very many combinations it may be that the resulting sort order is effectively the same &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort by a b c for:&lt;/P&gt;
&lt;P&gt;a b c&lt;/P&gt;
&lt;P&gt;1 2 3&lt;/P&gt;
&lt;P&gt;1 2 4&lt;/P&gt;
&lt;P&gt;1 2 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is the same result as sort by a c.&lt;/P&gt;
&lt;P&gt;but if your next data set looks like&lt;/P&gt;
&lt;P&gt;a b c&lt;/P&gt;
&lt;P&gt;1 2 3&lt;/P&gt;
&lt;P&gt;1 1 4&lt;/P&gt;
&lt;P&gt;1 2 4&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;0 5&lt;/P&gt;
&lt;P&gt;then the result of sorting by a b c differs from sorting by a c. So if you sort by a c and use by a b c you'll get the out of order error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HINT: Either copy the by statement from the sort to the by group processing procedure or vise versa.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 19:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307738#M65949</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-27T19:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307753#M65956</link>
      <description>&lt;P&gt;I recommend to sort the data before you run the last dataset. You mentioned that the code ran sucessfully for 1 month. I hope the data in that month is in the sort order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your case I assume when you run for 1month all observations has&amp;nbsp;"Client_Specialty_Flag"&amp;nbsp;&amp;nbsp;as &amp;nbsp;&lt;SPAN class="token string"&gt;"Specialty" .&amp;nbsp; When you run for 4 months maybe it may get "Non-Specialty" that appears in unsorted order.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token string"&gt;For example :&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token string"&gt;one dataset has all specialty and two dataset has mixed. then if we use "by" with set to unsorted data creates error. dataset one1 runs without errors and dataset two2&amp;nbsp;has errors&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; one;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; num type &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$15.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;1 specialty&lt;/P&gt;&lt;P&gt;2 specialty&lt;/P&gt;&lt;P&gt;3 specialty&lt;/P&gt;&lt;P&gt;4 specialty&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; two;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; num type &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$15.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;1 specialty&lt;/P&gt;&lt;P&gt;2 specialty&lt;/P&gt;&lt;P&gt;3 non-specialty&lt;/P&gt;&lt;P&gt;4 specialty&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; one1;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; one;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; type;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; two2;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; two;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; type;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 20:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307753#M65956</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-10-27T20:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307801#M65979</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice﻿&lt;/a&gt;&amp;nbsp;have an example of &lt;U&gt;each&lt;/U&gt; month is like:&lt;/P&gt;
&lt;P&gt;1 non_speicalty&lt;/P&gt;
&lt;P&gt;2 non_specialty&lt;/P&gt;
&lt;P&gt;3 specialty&lt;/P&gt;
&lt;P&gt;4 specialty&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so every month by itself is sorted &lt;STRONG&gt;ascending&lt;/STRONG&gt; ok.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now take two month, then you will get a non sorted data:&lt;/P&gt;
&lt;P&gt;1 non_speicalty&lt;/P&gt;
&lt;P&gt;2 non_specialty&lt;/P&gt;
&lt;P&gt;3 specialty&lt;/P&gt;
&lt;P&gt;4 specialty&lt;/P&gt;
&lt;P&gt;1 non_speicalty &amp;nbsp; &amp;nbsp;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; breaking point of ascending sort&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 non_specialty&lt;/P&gt;
&lt;P&gt;3 specialty&lt;/P&gt;
&lt;P&gt;4 specialty&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2016 01:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/307801#M65979</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-10-28T01:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: By Variables Not Properly Sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/308321#M66148</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;Thanks to all of you. You all pretty much had it right; When I finally looked at the data for one month, Client_Specialty_Flag was in the right order with all of the "Non-Specialty" coming before all "Specialty". Then, when ran for 2 or more months, since I didn't sort it before the data step&amp;nbsp;that I had the by's, the order got messed up as my data had a lot of "Specialty" before "Non-Specialty" within the same by-groups. Thank you everyone for your patience, I learned a lot about by groups/by statement in data step, and sorting.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 17:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-Variables-Not-Properly-Sorted/m-p/308321#M66148</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-10-31T17:00:44Z</dc:date>
    </item>
  </channel>
</rss>

