<?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: Help with practice SAS CODE in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/612055#M18279</link>
    <description>&lt;P&gt;The SAS log should show you where your errors are.&amp;nbsp; Have you tried to correct those?&amp;nbsp; Remember to fix the first error.&amp;nbsp; Later errors might just be caused by the SAS compiler being confused because of the first error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there some specific error in the log that you cannot figure out?&lt;/P&gt;
&lt;P&gt;If so then copy of and paste the log for that step.&amp;nbsp; Make sure to use the Insert Code button on the editor so that you can paste the lines from the log without the forum treating them as paragraphs.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2019 15:51:16 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-12-16T15:51:16Z</dc:date>
    <item>
      <title>Help with practice SAS CODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/611964#M18265</link>
      <description>&lt;P&gt;I tired correcting this code I was given. However, it is not working. How should I go about correcting it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;INITIALLY GIVEN:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OPTIONS PS = 58 LS = 8 NODAT NONUMBER&lt;/P&gt;&lt;P&gt;DATA sales;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; INPUT weekof mmddyy8. Store $ Mon Tues Wed Thur Fri; AvgSales = (Mon + Tues +&lt;/P&gt;&lt;P&gt;Wed + Thurs + Fri)/4; length Group $6;&lt;/P&gt;&lt;P&gt;lable weekof = 'Date;&lt;/P&gt;&lt;P&gt;if AvgSales = '.' then Group = 'N/A'; else if AvgSales LE 605 then Group = 'Low';&lt;/P&gt;&lt;P&gt;else if 605 LT AvgSales LE 750 then Group = 'Average'; else if AvgSales GT 75O&lt;/P&gt;&lt;P&gt;then Group = 'High'; if Store = 110 then region = 'South'; else if Store = 111 then&lt;/P&gt;&lt;P&gt;region = 'South';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GOAL IS TO GET THE FOLLOWING RESULTS - attached&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else if Store = 112 then region = 'North';&lt;/P&gt;&lt;P&gt;else if Store = 113 then region = 'North';&lt;/P&gt;&lt;P&gt;else if Store = 114 then region = North;&lt;/P&gt;&lt;P&gt;drop Mon Tues Wed Thur Fri;&lt;/P&gt;&lt;P&gt;DATALINES&lt;/P&gt;&lt;P&gt;10/12/07 11O 412 532 641 701 802&lt;/P&gt;&lt;P&gt;10/12/07 111 478 567 699 789 821&lt;/P&gt;&lt;P&gt;10/12/07 112 399 501 650 712 812&lt;/P&gt;&lt;P&gt;10/12/07 113 421 532 698 756 872&lt;/P&gt;&lt;P&gt;10/12/07 114 401 510 612 721 899&lt;/P&gt;&lt;P&gt;17/12/07 110 710 725 789 721 799&lt;/P&gt;&lt;P&gt;17/12/07 111 689 701 729 703 721&lt;/P&gt;&lt;P&gt;17/12/07 112 899 812 802 738 712&lt;/P&gt;&lt;P&gt;17/12/07 113 700 712 748 765 801&lt;/P&gt;&lt;P&gt;17/12/07 114 699 799 899 608&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;24/12/07 110 340 333 321 401 490&lt;/P&gt;&lt;P&gt;24/12/07 111 801 793 721 763 798&lt;/P&gt;&lt;P&gt;24/12/07 112 598 798 684 502 412&lt;/P&gt;&lt;P&gt;24/12/07 113 980 921 832 812 849&lt;/P&gt;&lt;P&gt;24/12/07 114 798 709 721 799 724&lt;/P&gt;&lt;P&gt;31/12/07 110 487 321 399 312 321&lt;/P&gt;&lt;P&gt;31/12/07 111 501 532 598 581 601&lt;/P&gt;&lt;P&gt;31/12/07 112 598 512 540 523 549&lt;/P&gt;&lt;P&gt;31/12/07 113 601 625 674 698 601&lt;/P&gt;&lt;P&gt;31/12/07 114 900 805 700 601 811&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN; PROC PRINT data = sales / label; RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HOW I HAVE CORRECTED IT SO - STILL NOT WORKING&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA sales;&lt;BR /&gt;input Date $ 1-8 Store 10-12 Mon 14-16 Tues 18-20 Wed 22-24 Thurs 26-28 Fri 30-32;&lt;BR /&gt;DATALINES;&lt;BR /&gt;10/12/07 110 412 532 641 701 802&lt;BR /&gt;10/12/07 111 478 567 699 789 821&lt;BR /&gt;10/12/07 112 399 501 650 712 812&lt;BR /&gt;10/12/07 113 421 532 698 756 872&lt;BR /&gt;10/12/07 114 401 510 612 721 899&lt;BR /&gt;17/12/07 110 710 725 789 721 799&lt;BR /&gt;17/12/07 111 689 701 729 703 721&lt;BR /&gt;17/12/07 112 899 812 802 738 712&lt;BR /&gt;17/12/07 113 700 712 748 765 801&lt;BR /&gt;17/12/07 114 699 799 899 608 .&lt;BR /&gt;24/12/07 110 340 333 321 401 490&lt;BR /&gt;24/12/07 111 801 793 721 763 798&lt;BR /&gt;24/12/07 112 598 798 684 502 412&lt;BR /&gt;24/12/07 113 980 921 832 812 849&lt;BR /&gt;24/12/07 114 798 709 721 799 724&lt;BR /&gt;31/12/07 110 487 321 399 312 321&lt;BR /&gt;31/12/07 111 501 532 598 581 601&lt;BR /&gt;31/12/07 112 598 512 540 523 549&lt;BR /&gt;31/12/07 113 601 625 674 698 601&lt;BR /&gt;31/12/07 114 900 805 700 601 811&lt;BR /&gt;;&lt;BR /&gt;AvgSales=(Mon + Tues + Wed + Thurs + Fri)/5; length Group $6; label week ='Date;&lt;BR /&gt;if (AvgSales = '.') then Group = N/A;&lt;BR /&gt;else if (AvgSales &amp;lt;= 605) then Group = Low;&lt;BR /&gt;else if (AvgSales 605 &amp;lt; sales &amp;lt;=750) then Group = Average;&lt;BR /&gt;else if (AvgSales sales &amp;gt;750) then Group = High;&lt;BR /&gt;if Store = 110 then region = South;&lt;BR /&gt;else if Store = 111 then region = South;&lt;BR /&gt;else if Store = 112 then region = North;&lt;BR /&gt;else if Store = 113 then region = North;&lt;BR /&gt;else if Store = 114 then region = North;&lt;BR /&gt;drop Mon Tues Wed Thur Fri;&lt;BR /&gt;OPTIONS PS = 58 LS = 8 NODAT NONUMBER&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT data=sales / label;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 06:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/611964#M18265</guid>
      <dc:creator>rkaur17</dc:creator>
      <dc:date>2019-12-16T06:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help with practice SAS CODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/612055#M18279</link>
      <description>&lt;P&gt;The SAS log should show you where your errors are.&amp;nbsp; Have you tried to correct those?&amp;nbsp; Remember to fix the first error.&amp;nbsp; Later errors might just be caused by the SAS compiler being confused because of the first error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there some specific error in the log that you cannot figure out?&lt;/P&gt;
&lt;P&gt;If so then copy of and paste the log for that step.&amp;nbsp; Make sure to use the Insert Code button on the editor so that you can paste the lines from the log without the forum treating them as paragraphs.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 15:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/612055#M18279</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-16T15:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help with practice SAS CODE</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/612081#M18280</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW you have a couple of issues that are admittedly newbie issues. SAS, unlike many general programming languages, has FUNCTIONS for a number of statistics such as MEAN, STD, SUM.&lt;/P&gt;
&lt;P&gt;If you&amp;nbsp; have missing values for any of the variables when you do A+B+C then the result will be missing. This is intentional documented behavior of the + operator. If you might have a missing value but want the sum of the non-missing values then use SUM(A,B,C).&lt;/P&gt;
&lt;P&gt;So you may want one of either&lt;/P&gt;
&lt;PRE&gt;AvgSales= sum(Mon , Tues , Wed , Thurs , Fri)/5;
if you want average per day sales
or perhaps

AvgSales= mean(Mon, Tues, Wed, Thurs, Fri); 
if you want average sales per day for the days with sales.&lt;/PRE&gt;
&lt;P&gt;The missing value is a numeric value for missing when using the period or dot. You should not enclose it quotes.&lt;/P&gt;
&lt;PRE&gt;if (AvgSales = '.') then Group = N/A;&lt;/PRE&gt;
&lt;P&gt;Should be throwing LOTS of errors because you probably do not have a variable named N/A and likely are intending to create a text variable named group with the value of "N/A" Which would be done with&lt;/P&gt;
&lt;PRE&gt;if (AvgSales = .) then Group = 'N/A';&lt;/PRE&gt;
&lt;P&gt;Similarly ALL the values of Group need to be inside quotes. You also will have an issue I the Group variable not having a defined length. So the first use in the code of Group = 'N/A' would set the length to 3 characters and the remaining values would be truncated.&lt;/P&gt;
&lt;P&gt;You need to specify a length for character variables before use in many cases to prevent this using the LENGTH statement &lt;STRONG&gt;before&lt;/STRONG&gt; the variable is used in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Length Group $ 7; creates a variable of 7 characters.&lt;/P&gt;
&lt;P&gt;Similar with your Region variable. Those should be character values in quotes instead of just South or North.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is another comparison operator called IN that allows you to compare multiple values to simplify some of the code:&lt;/P&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;if Store = 110 then region = 'South';
else if Store = 111 then region = 'South;'
else if Store = 112 then region = 'North';
else if Store = 113 then region = 'North';
else if Store = 114 then region = 'North';&lt;/PRE&gt;
&lt;P&gt;You can use&lt;/P&gt;
&lt;PRE&gt;if Store in (110 111) then region='South';
else if Store in (112 113 1140 then region = 'North';&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A slightly more advanced approach is to create a custom format to assign text based on a single variable value.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 17:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-practice-SAS-CODE/m-p/612081#M18280</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-16T17:13:19Z</dc:date>
    </item>
  </channel>
</rss>

