<?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: Hardcoding in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506864#M135905</link>
    <description>&lt;P&gt;You need the MAX() because you have an upper or lower bound, otherwise this would do groups from YYY5 to YYY5+9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;period = catx("-", max(round(year, 10)-5, 1976), max(round(year, 10)+4, 2026));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT this should probably be MIN instead of MAX at last argument.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;period = catx("-", max(round(year, 10)-5, 1976), min(round(year, 10)+4, 2026));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Oct 2018 18:43:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-10-23T18:43:10Z</dc:date>
    <item>
      <title>Hardcoding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506826#M135893</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Is there a way the below hardcoding be replaced by loops or arrays? &amp;nbsp; lower bound is 1986 and upper can be 2026&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; if 1976&amp;lt;= Manuf_Year &amp;lt; 1985 then TestYr="1976-1984";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if 1985&amp;lt;=Manuf_Year &amp;lt;1995&amp;nbsp; then TestYr="1985-1994";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if 1995 &amp;lt;= Manuf_Year LT 2005 then TestYr="1995-2004";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 14:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506826#M135893</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2018-10-23T14:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Hardcoding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506847#M135894</link>
      <description>&lt;P&gt;Use a do loop to build a control dataset for proc format; take care of the border cases in the loop.&lt;/P&gt;
&lt;P&gt;After that, it is a simple put() or format assignment:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
fmtname = "myfmt";
type = 'N';
do start = 1975 to 2025 by 10;
  end = start + 9;
  if start = 1976 then start = 1976;
  if end = 2034 then end = 2026;
  label = catx('-',start,end);
  output;
end;
run;

proc format cntlin=cntlin;
run;

data want;
input year;
format year myfmt.;
testyear = put(year,myfmt.);
cards;
1976
2010
2026
2020
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 14:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506847#M135894</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-23T14:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hardcoding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506858#M135901</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Is there a way the below hardcoding be replaced by loops or arrays? &amp;nbsp; lower bound is 1986 and upper can be 2026&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; if 1976&amp;lt;= Manuf_Year &amp;lt; 1985 then TestYr="1976-1984";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if 1985&amp;lt;=Manuf_Year &amp;lt;1995&amp;nbsp; then TestYr="1985-1994";&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else if 1995 &amp;lt;= Manuf_Year LT 2005 then TestYr="1995-2004";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You state "lower bound is 1986" and then do not display anything about the "upper bound", which is sort of implied by the example code. Do intend 10 year intervals such as 1986-1995?&lt;/P&gt;
&lt;P&gt;If so this may get you started.&lt;/P&gt;
&lt;PRE&gt;data work.cntlin;
   fmtname='tenyear';
   type='N';
   do start=1986 to 2026 by 10;
      end= start+9;
      label = catx('-',start,end);
      output;
   end;
run;

proc format library=work cntlin=work.cntlin;
run;

data example;
   input year;
   y = put(year,tenyear.);
datalines;
1988
1999
2001
2016
2030
;
run;&lt;/PRE&gt;
&lt;P&gt;You would have to ensure the format was available for use by either placing the format in a library on the FMTSEARCH path or rerunning it the format code. I suggest making sure the code doesn't get lost.&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;P&gt;Most of the time when you are wanting to display a value based on a single variable then a custom format may be appropriate.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 14:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506858#M135901</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-23T14:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Hardcoding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506864#M135905</link>
      <description>&lt;P&gt;You need the MAX() because you have an upper or lower bound, otherwise this would do groups from YYY5 to YYY5+9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;period = catx("-", max(round(year, 10)-5, 1976), max(round(year, 10)+4, 2026));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT this should probably be MIN instead of MAX at last argument.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;period = catx("-", max(round(year, 10)-5, 1976), min(round(year, 10)+4, 2026));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 18:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506864#M135905</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-23T18:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Hardcoding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506951#M135955</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;: Nice compact solution, where I'm sure you meant &lt;FONT face="courier new,courier"&gt;m&lt;STRONG&gt;in&lt;/STRONG&gt;(&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt; in the third argument of CATX.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 17:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506951#M135955</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-23T17:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hardcoding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506979#M135968</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;Yup, that would help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 18:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hardcoding/m-p/506979#M135968</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-23T18:42:08Z</dc:date>
    </item>
  </channel>
</rss>

