<?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: Multiple observations from one record - understanding the logic in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543735#M7755</link>
    <description>Okay, for that to be true a coule of things need to follow I think:&lt;BR /&gt;&lt;BR /&gt;1. The inputed values needs to remain in the memory after they've been outputed.&lt;BR /&gt;&lt;BR /&gt;2. the variable "sales" needs to be overwritten by the new variable with the same name.&lt;BR /&gt;&lt;BR /&gt;3. Despite (2), the second input statement picks a new value (one step to the right) for the new variable.&lt;BR /&gt;&lt;BR /&gt;Do I interpret this correctly?</description>
    <pubDate>Sat, 16 Mar 2019 15:12:30 GMT</pubDate>
    <dc:creator>Syntas_error</dc:creator>
    <dc:date>2019-03-16T15:12:30Z</dc:date>
    <item>
      <title>Multiple observations from one record - understanding the logic</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543715#M7752</link>
      <description>&lt;P&gt;This is from another SAS practice questoin.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have a raw data file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1001 77,164.19 76,804.75 74,384.27&lt;/P&gt;&lt;P&gt;1002 76,612.93 81,456.34 82,063.97&lt;/P&gt;&lt;P&gt;1003 82,185.16 79,742.33&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We want to transform the raw data file into the following data set:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Store&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sales&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Month&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77,164.19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;76,804.75&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74,384.27&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;76,612.93&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;81,456.34&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;82,063.97&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;82,185.16&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1003&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;79,742.33&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are several alternatives, to choose from, the correct one being:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;data perm.topstores;
infile&amp;nbsp;sales98&amp;nbsp;missover;
input Store Sales : comma. @;
Month=0;
do while (sales ne .);
month + 1;
output;
input sales : comma. @;
end;
run;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, could someone walk me through what's happening in the different steps?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I understand the virst relevant line:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;input Store Sales : comma. @;&lt;/PRE&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;This simply specifies the variables, the ':' alows us to use an informat for 'sales', so we can process those non-standard values. The&amp;nbsp;@-sign&amp;nbsp;should "lock the row into place" allowing multiple observations to be read from the same row. Though in my understanding, this would mean values from each row should be assigned to Store "and" Sales, so for the first row we would get something like:&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&lt;P&gt;Store&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sales&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77,164.19&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;76,804.75&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74,384.27&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;The next segment of code is hard to follow:&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;do while (sales ne .);
month + 1;
output;
input sales : comma. @;
end;&lt;/PRE&gt;&lt;DIV class="rteindent1"&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;What exactly does "do while (sales ne .);", mean, do we execute the steps as long as the values of sales aren't missing?&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;How exacly does this step specify that the counter is to be reset for each new store?&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2019 09:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543715#M7752</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2019-03-16T09:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple observations from one record - understanding the logic</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543725#M7753</link>
      <description>&lt;P&gt;The missover option tells SAS to return a missing value when you try to read more items than are present on the current line.&lt;/P&gt;
&lt;P&gt;The @ holds the input line.&lt;/P&gt;
&lt;P&gt;So the do while keeps reading from the input line until the end is reached (input returns a missing), at which point it goes to the next data step iteration, which causes an automatic skip to the next input line.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2019 12:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543725#M7753</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-16T12:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple observations from one record - understanding the logic</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543729#M7754</link>
      <description>&lt;P&gt;You've picked a good problem to deepen your understanding of how the DATA step works.&amp;nbsp; Here's where your logic breaks down.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INPUT statement is more than a roadmap on how to read the incoming lines of data.&amp;nbsp; It's actually a set of instructions, which execute repeatedly (for each line of data.&amp;nbsp; So for the first INPUT statement, and the first line of data, this is all you get:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Store&amp;nbsp; &amp;nbsp;Sales&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1001&amp;nbsp; &amp;nbsp; 77164.19&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Those values just sit in memory, awaiting further developments.&amp;nbsp; Next, the software adds MONTH, with a value of 0.&amp;nbsp; Then the DO loop begins, since SALES &amp;gt; . is true.&amp;nbsp; It increases MONTH, giving you:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Store&amp;nbsp; &amp;nbsp;Sales&amp;nbsp; &amp;nbsp; &amp;nbsp;Month&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1001&amp;nbsp; &amp;nbsp; 77164.19&amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The OUTPUT statement executes next, copying these values from memory to the output data set.&amp;nbsp; (Technically, I'm skipping a little bit of technical detail here, not important for our purposes.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the second INPUT statement executes, giving you:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Store&amp;nbsp; &amp;nbsp;Sales&amp;nbsp; &amp;nbsp; &amp;nbsp;Month&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1001&amp;nbsp; &amp;nbsp; 76804.75&amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, those values are just sitting in memory.&amp;nbsp; The DO loop continues, increasing MONTH to 2.&amp;nbsp; Then the OUTPUT statement executes again, copying the current values from memory to the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DO loop again checks the value of SALES and finds that it is greater than missing.&amp;nbsp; So the DO loop executes again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a nutshell, those are the next principles to absorb, to increase your understanding of the DATA step.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2019 13:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543729#M7754</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-16T13:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple observations from one record - understanding the logic</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543735#M7755</link>
      <description>Okay, for that to be true a coule of things need to follow I think:&lt;BR /&gt;&lt;BR /&gt;1. The inputed values needs to remain in the memory after they've been outputed.&lt;BR /&gt;&lt;BR /&gt;2. the variable "sales" needs to be overwritten by the new variable with the same name.&lt;BR /&gt;&lt;BR /&gt;3. Despite (2), the second input statement picks a new value (one step to the right) for the new variable.&lt;BR /&gt;&lt;BR /&gt;Do I interpret this correctly?</description>
      <pubDate>Sat, 16 Mar 2019 15:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543735#M7755</guid>
      <dc:creator>Syntas_error</dc:creator>
      <dc:date>2019-03-16T15:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple observations from one record - understanding the logic</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543744#M7756</link>
      <description>&lt;P&gt;Pretty much.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Values for the current observation are always "in memory" during the execution of a data step.&amp;nbsp; That is why you can use the variables in operations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variables are not really "overwritten".&amp;nbsp; They have values. The values vary across observations of the dataset and can vary during the execution of the code. Remember that SAS will compile your data step code before it starts running it. So the INPUT statement itself doesn't define a variable. I just reads values into the variable.&amp;nbsp; It might appear to define the variable because allows lazy programming.&amp;nbsp; You don't have to define your variables before using them. SAS will make a guess at how to define the variable based on how you first use it in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS keeps a pointer to where on the line you are currently reading.&amp;nbsp; (You can use the COLUMN= option on the INFILE statement to have it share that value as a variable in your data step.)&amp;nbsp; So when you again read SALES it starts looking from where it left off after the last read (because of the trialing&amp;nbsp;@ on the input statement).&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2019 16:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543744#M7756</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-16T16:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple observations from one record - understanding the logic</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543796#M7764</link>
      <description>&lt;P&gt;You interpret correctly.&amp;nbsp; While this is an oversimplification, it helps to think of there being three storage locations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The raw data line that the program reads from&lt;/LI&gt;
&lt;LI&gt;The values in memory&lt;/LI&gt;
&lt;LI&gt;The values written to the output data set&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to address your questions ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The OUTPUT statement copies from values in memory to the output data set.&amp;nbsp; It has no impact on the values in memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Overwriting SALES" means changing the value of SALES in memory.&amp;nbsp; In this case, that is accomplished by executing an INPUT statement that reads from the raw data line, and replaces the value in memory.&amp;nbsp; So it's not a new variable with the same name ... it's the value in memory being replaced by a new value.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 13:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiple-observations-from-one-record-understanding-the-logic/m-p/543796#M7764</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-17T13:33:34Z</dc:date>
    </item>
  </channel>
</rss>

