<?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 to input numerical range in a data step and use it to define a format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901435#M356248</link>
    <description>&lt;P&gt;When SAS begins to work with this DATA step code, the first time it encounters variables START and END is in the LENGTH statement, which makes them character variables. After that, the DATA step will treat these variable as character variables.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2023 16:26:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-11-03T16:26:31Z</dc:date>
    <item>
      <title>how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901421#M356242</link>
      <description>&lt;P&gt;For the following simple sas code,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;data myfmt&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;retain fmtname &lt;/SPAN&gt;&lt;SPAN class=""&gt;"salegroup"&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;length start $20 label $20&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;infile datalines delimiter&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;'/'&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;input start $ label $&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;datalines&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;low&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;700&lt;/SPAN&gt; &lt;SPAN class=""&gt;/&lt;/SPAN&gt;&lt;SPAN class=""&gt; need improvement&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;700&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;900&lt;/SPAN&gt; &lt;SPAN class=""&gt;/&lt;/SPAN&gt;&lt;SPAN class=""&gt; good&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;900&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt;high &lt;/SPAN&gt;&lt;SPAN class=""&gt;/&lt;/SPAN&gt;&lt;SPAN class=""&gt; top sale&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;run&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;proc format cntlin&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;myfmt fmtlib&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;run&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;P&gt;When I run the code, SAS complains the following&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;70&lt;/SPAN&gt;&lt;SPAN class=""&gt; proc format cntlin&lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;myfmt fmtlib&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;ERROR&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;For&lt;/SPAN&gt;&lt;SPAN class=""&gt; format SALEGROUP&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;this&lt;/SPAN&gt;&lt;SPAN class=""&gt; range &lt;/SPAN&gt;&lt;SPAN class=""&gt;is&lt;/SPAN&gt;&lt;SPAN class=""&gt; repeated&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt;&lt;SPAN class=""&gt; values overlap&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;.-..&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN class=""&gt;I use the most conventional way to write the same functionality as the following,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;proc format fmtlib&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;value salegroupv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;low&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;700&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;'need improvement'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;700&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;900&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;'good'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;900&lt;/SPAN&gt;&lt;SPAN class=""&gt;-&lt;/SPAN&gt;&lt;SPAN class=""&gt;high &lt;/SPAN&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;'top sale'&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;run&lt;/SPAN&gt;&lt;SPAN class=""&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN class=""&gt;and it seems it works fine. Why is this difference? How can I possibly use the first way to define a numeric range to format my data?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Nov 2023 15:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901421#M356242</guid>
      <dc:creator>Newlifewithegg</dc:creator>
      <dc:date>2023-11-03T15:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901424#M356244</link>
      <description>&lt;P&gt;See&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p0owa4ftikc2ekn1q0rmpulg86cx.htm#p05g1cdvff8h8tn1frtzxrnkzezo" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p0owa4ftikc2ekn1q0rmpulg86cx.htm#p05g1cdvff8h8tn1frtzxrnkzezo&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It says, among other things:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;If you are creating a format with ranges of input values, then you must specify the END variable. If range values are to be noninclusive, then the variables SEXCL and EEXCL must each have a value of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class="xisDoc-variableValue"&gt;Y&lt;/CODE&gt;. Inclusion is the default.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't have an END variable. Example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1e19y6lrektafn1kj6nbvhus59w.htm#n1e19y6lrektafn1kj6nbvhus59w" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1e19y6lrektafn1kj6nbvhus59w.htm#n1e19y6lrektafn1kj6nbvhus59w&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 16:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901424#M356244</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-03T16:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901430#M356245</link>
      <description>&lt;P&gt;Thanks for the hint, the following is the corrected sas code to make life easier for newcomers in case,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data myfmt;&lt;BR /&gt;retain fmtname "salegroup";&lt;BR /&gt;length start SEXCL end EEXCL label $20;&lt;BR /&gt;infile datalines delimiter='/';&lt;BR /&gt;input start sexcl end eexcl label $;&lt;BR /&gt;datalines;&lt;BR /&gt;low / n / 700 / y / need improvement&lt;BR /&gt;700 / n / 900 / y / good&lt;BR /&gt;900 / n / 1000 / n / top sale&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc format cntlin=myfmt fmtlib;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 16:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901430#M356245</guid>
      <dc:creator>Newlifewithegg</dc:creator>
      <dc:date>2023-11-03T16:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901431#M356246</link>
      <description>still, a quick question here, n, y seems to be character, why would SEXCL/EEXCL defined as numeric yet still successfully read in these two entries?</description>
      <pubDate>Fri, 03 Nov 2023 16:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901431#M356246</guid>
      <dc:creator>Newlifewithegg</dc:creator>
      <dc:date>2023-11-03T16:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901435#M356248</link>
      <description>&lt;P&gt;When SAS begins to work with this DATA step code, the first time it encounters variables START and END is in the LENGTH statement, which makes them character variables. After that, the DATA step will treat these variable as character variables.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 16:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901435#M356248</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-03T16:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901436#M356249</link>
      <description>&lt;P&gt;"Low" and "High" range elements can also be specified in the data set by setting the HLO variable to include "L" for low and/or "H" for high .&lt;/P&gt;
&lt;P&gt;"O" , that's a capital letter o, is for the range value "Other" .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create a full data set containing the result of creating a format with the CNTLOUT option such as:&lt;/P&gt;
&lt;PRE&gt;proc format cntlin=myfmt cntlout=fmtout;
run;&lt;/PRE&gt;
&lt;P&gt;If you look in the Fmtout data set created you will see the HLO variable with the value L.&lt;/P&gt;
&lt;P&gt;The HLO variable may be more needed if you create datasets that create multiple formats at one time.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 16:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901436#M356249</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-03T16:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901437#M356250</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;When SAS begins to work with this DATA step code, the first time it encounters variables START and END is in the LENGTH statement, which makes them character variables. After that, the DATA step will treat these variable as character variables.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;so, basically $20 has been applied to all the variables before it? If the case, how to restrict start, end etc to be only numeric but let the last one to have the $20 property?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 16:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901437#M356250</guid>
      <dc:creator>Newlifewithegg</dc:creator>
      <dc:date>2023-11-03T16:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901441#M356251</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/443962"&gt;@Newlifewithegg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;so, basically $20 has been applied to all the variables before it? If the case, how to restrict start, end etc to be only numeric but let the last one to have the $20 property?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In the example, BEGIN and END are character variables, because values of LOW, HIGH or OTHER are valid values. If you don't want them all as length 20 you could do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length start $10 SEXCL $2 end $10 EEXCL $2 label $20;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2023 16:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901441#M356251</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-03T16:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to input numerical range in a data step and use it to define a format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901444#M356252</link>
      <description>&lt;P&gt;Read the documentation of the LENGTH statement.&lt;/P&gt;
&lt;P&gt;This will make START and END as numeric and SEXCL and EEXCL as $1 instead of $20.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length start 8 SEXCL $1 end 8 EEXCL $1 label $20;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also you don't need the $ in the INPUT statement if you have already defined LABEL as character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input start sexcl end eexcl label ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course you cannot read LOW and HIGH into START and END if they are numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data myfmt;
  length fmtname $32 start end 8 SEXCL EEXCL $1 HLO $3 label $20;
  retain fmtname "salegroup";
  infile datalines dsd dlm='/' truncover ;
  input start sexcl end eexcl hlo label ;
datalines;
    / n /  700 / y / L / need improvement
700 / n /  900 / y /   / good
900 / n / 1000 / n /   / top sale
1000 / y /    / n / H / WOW!!
;

proc format cntlin=myfmt fmtlib;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;----------------------------------------------------------------------------
|                    FORMAT NAME: SALEGROUP LENGTH: 16                     |
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:  16  FUZZ: STD       |
|--------------------------------------------------------------------------|
|START           |END             |LABEL  (VER. 9.4     03NOV2023:13:08:47)|
|----------------+----------------+----------------------------------------|
|LOW             |             700&amp;lt;need improvement                        |
|             700|             900&amp;lt;good                                    |
|             900|            1000|top sale                                |
|            1000&amp;lt;HIGH            |WOW!!                                   |
----------------------------------------------------------------------------
&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2023 17:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-input-numerical-range-in-a-data-step-and-use-it-to-define/m-p/901444#M356252</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-11-03T17:23:24Z</dc:date>
    </item>
  </channel>
</rss>

