<?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: use range as a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404390#M98299</link>
    <description>&lt;P&gt;If you don't specify a length for a character variable it takes as its length the length of the first value assigned to it. In your case there must be a value of either 1 or 5 as the first value in the data so agegroup has a length of 3 ('&amp;lt;30').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can correct this by adding&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length agegroup  $5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before your set statement&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2017 07:42:00 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2017-10-16T07:42:00Z</dc:date>
    <item>
      <title>use range as a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404379#M98295</link>
      <description>&lt;P&gt;Hi, this might sound stupid, but i have been looking for the answer for last few hours, but I still can't figure this out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code shows how I define my 'agegroup' variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if i in (1, 5) then agegroup = '&amp;lt;30';
	else if i in (2, 6) then agegroup = '31-45';
	else if i in (3, 7) then agegroup = '46-60';
		else agegroup = '60+';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But my sas output eliminates the number after the dash:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.PNG" style="width: 85px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15908i083B7FFA400DD7D7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.PNG" alt="2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;thought this might be a problem about variable type, but I am not sure anymore. I also tried to replace the single quote with double quote, but it isn't working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 06:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404379#M98295</guid>
      <dc:creator>mingy</dc:creator>
      <dc:date>2017-10-16T06:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: use range as a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404390#M98299</link>
      <description>&lt;P&gt;If you don't specify a length for a character variable it takes as its length the length of the first value assigned to it. In your case there must be a value of either 1 or 5 as the first value in the data so agegroup has a length of 3 ('&amp;lt;30').&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can correct this by adding&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length agegroup  $5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before your set statement&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 07:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404390#M98299</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-10-16T07:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: use range as a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404392#M98300</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt; gave you the explanation to your problem.&lt;/P&gt;
&lt;P&gt;Instead of creating a new variable, you can use a format :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value agegroup
		1,5='&amp;lt;30'
		2,6='31-45'
		3,7='46-60'
		other='60+'
;
run;

proc print data=have;
	format i agegroup.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Oct 2017 07:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404392#M98300</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-10-16T07:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: use range as a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404398#M98302</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"In your case there must be a value of either 1 or 5 as the first value in the data so agegroup has a length of 3&amp;nbsp;"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variables get defined&amp;nbsp;during the compilation phase and before data step iteration so what's in the data doesn't matter. The full reason for a length of 3 is, that this is the length of the first value assignment in the code:&amp;nbsp; &amp;nbsp;&lt;EM&gt;then agegroup = '&lt;STRONG&gt;&amp;lt;30&lt;/STRONG&gt;'&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 08:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-range-as-a-variable/m-p/404398#M98302</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-16T08:08:32Z</dc:date>
    </item>
  </channel>
</rss>

