<?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: IF-THEN in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616693#M180571</link>
    <description>&lt;P&gt;Thank You very much for both of you &lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_8" style="color: rgb(0, 125, 195);" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097" target="_self"&gt;&lt;SPAN class="login-bold"&gt;@ed_sas_member&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp; and &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank"&gt;@PaigeMiller&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 11 Jan 2020 16:20:43 GMT</pubDate>
    <dc:creator>souji</dc:creator>
    <dc:date>2020-01-11T16:20:43Z</dc:date>
    <item>
      <title>IF-THEN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616683#M180565</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am still learning, please let me know my code is correct for below scenario / correct me if I am wrong:&lt;/P&gt;
&lt;P&gt;1. Create three data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; Young15&lt;/STRONG&gt;:people who are age 30 and younger.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Mid15:&lt;/STRONG&gt; people between the age of 40 and 60 , inclusive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;NotasYoung15&lt;/STRONG&gt;: people who are age&amp;nbsp;61 and older&lt;/P&gt;
&lt;P&gt;2.Remove the variables &lt;STRONG&gt;Test3, Test4,Test5&lt;/STRONG&gt; from the &lt;STRONG&gt;Young15&lt;/STRONG&gt; dataset&lt;/P&gt;
&lt;P&gt;3.Create New variable &lt;STRONG&gt;avgTest&lt;/STRONG&gt; that is the average of the &lt;STRONG&gt;reaming Test variables&lt;/STRONG&gt; for &amp;nbsp;&lt;STRONG&gt;Young15&lt;/STRONG&gt; dataset&lt;/P&gt;
&lt;P&gt;4. what is the &lt;STRONG&gt;average (mean) of&lt;/STRONG&gt; the &lt;STRONG&gt;Test5&lt;/STRONG&gt; variable in the &lt;STRONG&gt;NotasYoung15&lt;/STRONG&gt; data set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Young15 (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=Test3 Test4 Test5) Mid15 NotsaYoung15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SOUJ.input15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; age&amp;lt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;39&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Young15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;40&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;lt;=age&amp;lt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;60&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Mid15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; age&amp;gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;61&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NotasYoung15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.Young15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.Young15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;avgInc=mean(of Test: ); /*3*/&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.NotsaYoung15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.NotsaYoung15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;avgInc2=mean(of Test5); /* 4*/&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&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;</description>
      <pubDate>Sat, 11 Jan 2020 14:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616683#M180565</guid>
      <dc:creator>souji</dc:creator>
      <dc:date>2020-01-11T14:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616687#M180568</link>
      <description>&lt;P&gt;I would like to point out that creating separate data sets for this task is just unnecessary work. All of the questions can be answered by using the original data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;4. what is the &lt;STRONG&gt;average (mean) of&lt;/STRONG&gt; the &lt;STRONG&gt;Test5&lt;/STRONG&gt; variable in the &lt;STRONG&gt;NotasYoung15&lt;/STRONG&gt; data set&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the mean of single variable, you don't need the mean() function at all. If the question wants the "mean" on each row, the mean of a single variable in a row is simply the value of that variable. Unless of course, as it seems to me to be much more likely, #4 means that you want the mean of all records for the variable Test5, in other words the mean down the column (this is not what the mean() function does), you would need to use PROC MEANS.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 15:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616687#M180568</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-11T15:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616688#M180569</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301371"&gt;@souji&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I totally agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;'s comment.&lt;/P&gt;
&lt;P&gt;If the request is really to create 3 datasets, you code is good.&lt;/P&gt;
&lt;P&gt;Just 2 mistakes at first sight:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Replace 39 by 30 in the following statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if age&amp;lt;=39 then output Young15;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- Use the requested variable name (i.e. avgtest) for question #3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	avgInc=mean(of Test:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- For question #4, the mean() function will calculate the mean by rows (meaning you need to specify several variables). If you specify only one, then the mean is the value of this variable. To compute the mean of a 'column' (-&amp;gt; a variable), you can use PROC MEANS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data= work.NotsaYoung15 mean;
	var Test5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 15:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616688#M180569</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-11T15:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616693#M180571</link>
      <description>&lt;P&gt;Thank You very much for both of you &lt;A class="lia-link-navigation lia-page-link lia-user-name-link" id="link_8" style="color: rgb(0, 125, 195);" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097" target="_self"&gt;&lt;SPAN class="login-bold"&gt;@ed_sas_member&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp; and &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank"&gt;@PaigeMiller&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 16:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616693#M180571</guid>
      <dc:creator>souji</dc:creator>
      <dc:date>2020-01-11T16:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616694#M180572</link>
      <description>&lt;P&gt;actually, typo&amp;nbsp;error, it was 39&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Young15:&amp;nbsp; P&lt;/STRONG&gt;eople who are age&lt;STRONG&gt; 39&lt;/STRONG&gt; and younger&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;still I am correct right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; age&amp;lt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;39&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Young15;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 16:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616694#M180572</guid>
      <dc:creator>souji</dc:creator>
      <dc:date>2020-01-11T16:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616746#M180611</link>
      <description>Not being flippant, but you should open your data set and check it, not ask.</description>
      <pubDate>Sun, 12 Jan 2020 01:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN/m-p/616746#M180611</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-12T01:16:49Z</dc:date>
    </item>
  </channel>
</rss>

