<?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: Loop and length statement in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521274#M6730</link>
    <description>&lt;P&gt;Your if and else if conditions should be mutually exclusive :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data golf;
	
	set golf;
	length Distance_Catagory $20;
	 
	 
	 if Distance_Yards&amp;lt;290 then do;
	 Distance_Catagory='Poor';
	 end;
	 
	 if 290 &amp;lt;= Distance_Yards &amp;lt;=310 then do;
	 Distance_Catagory='Average';
	 end;
	
	 if Distance_Yards &amp;gt; 310 then do;
	 Distance_Catagory='Above Average';
	 end;
	 
	 
run;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Dec 2018 20:02:00 GMT</pubDate>
    <dc:creator>r_behata</dc:creator>
    <dc:date>2018-12-13T20:02:00Z</dc:date>
    <item>
      <title>Loop and length statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521272#M6729</link>
      <description>&lt;P&gt;I'm using SAS Studio online, I"m having trouble setting the character length and in the last if statement of my loop also won't work, any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;This is my code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data golf;&lt;BR /&gt;	infile '/home/c153469110/golf.txt';&lt;BR /&gt;	input Distance_yards 18-22&lt;BR /&gt;		  Golfer_ID 28-29&lt;BR /&gt;		  Brand $ 39;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=golf;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Data golf;&lt;BR /&gt;	&lt;BR /&gt;	set golf;&lt;BR /&gt;	length Distance_Catagory $20;&lt;BR /&gt;	 &lt;BR /&gt;	 &lt;BR /&gt;	 if Distance_Yards&amp;lt;290 then do;&lt;BR /&gt;	 Distance_Catagory='Poor';&lt;BR /&gt;	 end;&lt;BR /&gt;	 &lt;BR /&gt;	 if Distance_Yards&amp;gt;=290 and Distance_Yards&amp;lt;=310 then do;&lt;BR /&gt;	 Distance_Catagory='Average';&lt;BR /&gt;	 end;&lt;BR /&gt;	&lt;BR /&gt;	 if Distance_Yards&amp;lt;=310 then do;&lt;BR /&gt;	 Distance Catagory='Above Average';&lt;BR /&gt;	 end;&lt;BR /&gt;	 &lt;BR /&gt;	 &lt;BR /&gt;run;&lt;BR /&gt;	 &lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2018 19:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521272#M6729</guid>
      <dc:creator>KatieMessi</dc:creator>
      <dc:date>2018-12-13T19:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and length statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521274#M6730</link>
      <description>&lt;P&gt;Your if and else if conditions should be mutually exclusive :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data golf;
	
	set golf;
	length Distance_Catagory $20;
	 
	 
	 if Distance_Yards&amp;lt;290 then do;
	 Distance_Catagory='Poor';
	 end;
	 
	 if 290 &amp;lt;= Distance_Yards &amp;lt;=310 then do;
	 Distance_Catagory='Average';
	 end;
	
	 if Distance_Yards &amp;gt; 310 then do;
	 Distance_Catagory='Above Average';
	 end;
	 
	 
run;
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2018 20:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521274#M6730</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-12-13T20:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and length statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521282#M6731</link>
      <description>&lt;P&gt;Just going to add two things to this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you code with the input and output data set having the same name, it becomes harder to debug and you destroy your source data so you have to re-read it in again. For small data sets this is fine, for larger ones it can be quite problematic. And Category is spelled incorrectly &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;golf&lt;/STRONG&gt;&lt;/FONT&gt;; &lt;FONT size="4" color="#800080"&gt;&lt;STRONG&gt;*choose a different name to avoid overwriting your original data;&lt;/STRONG&gt;&lt;/FONT&gt;
	
	set golf;
	length Distance_Cat&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;a&lt;/STRONG&gt;&lt;/FONT&gt;gory $20;&lt;FONT color="#800080"&gt;&lt;STRONG&gt; *spelled incorrectly;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/251070"&gt;@KatieMessi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm using SAS Studio online, I"m having trouble setting the character length and in the last if statement of my loop also won't work, any help would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;This is my code...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data golf;&lt;BR /&gt;	infile '/home/c153469110/golf.txt';&lt;BR /&gt;	input Distance_yards 18-22&lt;BR /&gt;		  Golfer_ID 28-29&lt;BR /&gt;		  Brand $ 39;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=golf;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Data golf;&lt;BR /&gt;	&lt;BR /&gt;	set golf;&lt;BR /&gt;	length Distance_Catagory $20;&lt;BR /&gt;	 &lt;BR /&gt;	 &lt;BR /&gt;	 if Distance_Yards&amp;lt;290 then do;&lt;BR /&gt;	 Distance_Catagory='Poor';&lt;BR /&gt;	 end;&lt;BR /&gt;	 &lt;BR /&gt;	 if Distance_Yards&amp;gt;=290 and Distance_Yards&amp;lt;=310 then do;&lt;BR /&gt;	 Distance_Catagory='Average';&lt;BR /&gt;	 end;&lt;BR /&gt;	&lt;BR /&gt;	 if Distance_Yards&amp;lt;=310 then do;&lt;BR /&gt;	 Distance Catagory='Above Average';&lt;BR /&gt;	 end;&lt;BR /&gt;	 &lt;BR /&gt;	 &lt;BR /&gt;run;&lt;BR /&gt;	 &lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 21:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521282#M6731</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-13T21:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and length statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521283#M6732</link>
      <description>&lt;P&gt;1) As your longest&amp;nbsp; Distance_yards is&amp;nbsp;'Above Average' then its minimum required length is $13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Defining length as $20 will not take space of 20 char at print but 13 chars only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) The proposed code by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;&amp;nbsp;can be shorten to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data golf;
	set golf;
	length Distance_Catagory $20;
	 
	 if Distance_Yards &amp;lt;  290 then Distance_Catagory='Poor'; else
	 if Distance_Yards &amp;lt;= 310 then Distance_Catagory='Average'; else
	                               Distance Catagory='Above Average';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 21:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521283#M6732</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-12-13T21:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Loop and length statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521340#M6733</link>
      <description>&lt;P&gt;For a large number of uses you do not need to add a variable to accomplish this:&lt;/P&gt;
&lt;PRE&gt;	 
	 if Distance_Yards&amp;lt;290 then do;
	 Distance_Catagory='Poor';
	 end;
	 
	 if Distance_Yards&amp;gt;=290 and Distance_Yards&amp;lt;=310 then do;
	 Distance_Catagory='Average';
	 end;
	
	 if Distance_Yards&amp;lt;=310 then do;
	 Distance Catagory='Above Average';
	 end;
&lt;/PRE&gt;
&lt;P&gt;when a single variable needs to be displayed differently or groups created a format is often a more flexible tool. Please see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format libray=work;
value gd
0   - &amp;lt; 290 = 'Poor'
290 -   310 = 'Average'
310&amp;lt;- high  = 'Above Average'
;
run;

proc freq data=golf;
   tables distance_yards;
   format distance_yards gd.;
run;&lt;/PRE&gt;
&lt;P&gt;One of the major flexibilities is that if I decide that I want to have a 5 category response I create a new format and then use the new format with the analysis or data display. No need to go back through the data to create another variable. Formats may also be made from data sets. So you could possibly use something like Proc Rank to create 10 or 15 groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With numeric values the &amp;lt; are analogous to greater than or less than depending on location&lt;/P&gt;
&lt;P&gt;0 - &amp;lt; 290&amp;nbsp; means [0, 290) where 0 is included and values up to but not including 290&lt;/P&gt;
&lt;P&gt;290 - 310 means [290,310]&amp;nbsp; the endpoints are included&lt;/P&gt;
&lt;P&gt;310 &amp;lt;- high means (310, infinity) are included.&lt;/P&gt;
&lt;P&gt;The key words LOW and HIGH are used for the smallest and largest values SAS will recognize.&lt;/P&gt;
&lt;P&gt;This approach also makes it easy to ensure non-overlapping groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW you can rewrite&lt;/P&gt;
&lt;PRE&gt;Distance_Yards&amp;gt;=290 and Distance_Yards&amp;lt;=310 &lt;/PRE&gt;
&lt;P&gt;as either of these forms&lt;/P&gt;
&lt;PRE&gt;290 &amp;lt;= Distance_yards &amp;lt;= 310
290 le Distance_yards le 310&lt;/PRE&gt;
&lt;P&gt;which many programming languages don't allow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 00:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Loop-and-length-statement/m-p/521340#M6733</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-14T00:57:35Z</dc:date>
    </item>
  </channel>
</rss>

