<?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 Format Error: Start is greater than end in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352082#M63969</link>
    <description>&lt;P&gt;That code you provide works fine for me. &amp;nbsp;You must have other problems, for instance maybe data further on does not have the required rows or values. &amp;nbsp;Run it and see what is in the dataset&amp;nbsp;for_fmt_conflicts, you can filter it for start &amp;gt; end.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2017 07:59:24 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-04-21T07:59:24Z</dc:date>
    <item>
      <title>Proc Format Error: Start is greater than end</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352081#M63968</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to create dummies in SAS. My plan is, everytime AnnouncementDate ne . I want to make a variable called event=2 and the next one also (event=2) as well as the five previous observations 1 And all this flagged if the Previous 5 observations and the day after the announcement date are not empty. and in a by class (by stock for example). If this now switches to the next stock, it should start over and not take the previous observations into account.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my current code for an example dataset that I got help with below. But at the proc format step it says: ERROR: Start is greater than end. I tried removing the $ or sort by start. nothing works...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankful for any help!&lt;/P&gt;&lt;PRE&gt;data have;
input date announcementdate event_want conflict_want $;
datalines;
1115 . . .
2115 . . .
3115 . . .
4115 . . .
5115 . . .
6115 . 1 .
7115 . 1 .
8115 . 1 .
9115 . 1 .
10115 . 1 .
11115 1115 2 .
12115 . 2 .
13115 . . .
14115 . 1 .
16115 . 1 .
17115 . 1 .
18115 . 1 .
19115 . 1 .
20115 20115 2 .
21115 . 1 Y
21115 . 1 Y
22115 22115 2 Y
23115 . 2 Y
24115 . . .
25115 . . .
;;;;
run;

data for_fmt;
  set have nobs=nobs;
  length fmtname $16;
  fmtname = 'eventf';

  if _n_=1 then do;   *HLO='o' gives the 'other' value;
    start=.;
    end  =.;
    label = ' ';
    hlo='o';
    output;
  end;
  hlo=' ';

  if not missing(announcementdate) then do;
    start = max(1,_n_-5);
    end   = max(1,_n_-1);
    label='1';
    output;
    start = _n_;
    end   = min(_n_+1,nobs);
    label='2';
    output;
  end;
run;  *now we have a dataset of the ranges - but they overlap;

data for_fmt_conflicts;

  merge for_fmt(in=a) for_fmt(in=_in_next firstobs=2 keep=start rename=start=next_start); *look-ahead merge;
  retain new_start conflict_marker;
  if hlo='o' then do;    *again the 'other' row;
    output;
    fmtname='conflictf';
    output;
  end;
  else if end gt next_start and (_in_next) then do;   *if the next row will be a conflict, adjust the end back one and indicate where next should start;
    end = end-1;
    new_start = end+1;
    conflict_marker=1;
    output;
  end;
  else if conflict_marker=1 then do;  *if this is a conflict row type 1;
    start = new_start;
    output;
    fmtname='conflictf';
    label  ='Y';
    output;
    conflict_marker=2;
  end;
  else if conflict_marker=2 then do;  *if this is the 2s for a conflict row;
    output;
    fmtname='conflictf';
    label  ='Y';
    output;
    conflict_marker=0;
  end;
  else output;
run;
proc sort data=for_fmt_conflicts;  *must sort to get fmtnames grouped together;
  by fmtname start;
run;
proc format cntlin=for_fmt_conflicts;  *import formats;
quit;

data want;  *now apply formats;
  set have;
  event = put(_n_,eventf.);
  conflict = put(_n_,conflictf.);
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 07:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352081#M63968</guid>
      <dc:creator>MarcBoh</dc:creator>
      <dc:date>2017-04-21T07:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Error: Start is greater than end</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352082#M63969</link>
      <description>&lt;P&gt;That code you provide works fine for me. &amp;nbsp;You must have other problems, for instance maybe data further on does not have the required rows or values. &amp;nbsp;Run it and see what is in the dataset&amp;nbsp;for_fmt_conflicts, you can filter it for start &amp;gt; end.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 07:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352082#M63969</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-21T07:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Error: Start is greater than end</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352085#M63970</link>
      <description>&lt;P&gt;It has several where start&amp;gt;end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where does that happen? I don't see the issue....&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 08:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352085#M63970</guid>
      <dc:creator>MarcBoh</dc:creator>
      <dc:date>2017-04-21T08:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Error: Start is greater than end</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352087#M63971</link>
      <description>&lt;P&gt;I don't know what the question is. &amp;nbsp;The error is quite clear however, you cannot have a format where the start of the range is after the end of the range, hence you would need to fix the dataset which goes into the format procedure - the data you posted does not illustrate this.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 08:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352087#M63971</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-21T08:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Error: Start is greater than end</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352088#M63972</link>
      <description>&lt;P&gt;The question is, where in the code the start value gets bigger than the end. My logic seems to be wrong here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I deduct 2 from the new_start value and make it start, there are a lot of overlapping ranges.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 08:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352088#M63972</guid>
      <dc:creator>MarcBoh</dc:creator>
      <dc:date>2017-04-21T08:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Error: Start is greater than end</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352090#M63973</link>
      <description>&lt;P&gt;Please note the text:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;the data you posted does not illustrate this"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am not sitting at your desk looking at your data, the data you posted does not illustrate the problem.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What is it your actually trying to do here? &amp;nbsp;It looks like you creating a format based on a range of observation numbers. &amp;nbsp;That doesn't seem like a good idea - logical position in a dataset is not fixed (sorts for instance will change that). &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you want to flag certain records, then retain the flag variables and do your logic as you go through the dataset. &amp;nbsp;You seem to be doing this anyways in the dataset which creates the formats dataset, just remove the formats part and do that directly on your data?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 08:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Format-Error-Start-is-greater-than-end/m-p/352090#M63973</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-21T08:32:01Z</dc:date>
    </item>
  </channel>
</rss>

