<?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: Practice Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241230#M44692</link>
    <description>&lt;P&gt;The best way to understand SAS programming is to play with small examples, such as :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INFO;
input @1 Company $20. @25 State $2. @;
if State='  '  then input @30 Year;
else input @30 City Year;
input NumEmployees;
datalines;
Some Place Inc.         CA   123456     2012
10
Nowhere Ltd                             2013
100
Every Where Corp.       VT   654321     2014
1000
;

proc print data=info noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's only when I tried this that I realized that City was defined as a number.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Dec 2015 16:10:56 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-12-30T16:10:56Z</dc:date>
    <item>
      <title>Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241161#M44653</link>
      <description>&lt;P class="quiz-report-question"&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV&gt;&lt;STRONG&gt;The following SAS program is submitted:&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="rteindent1"&gt;&lt;EM&gt;data WORM.INFO;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;infile 'DATAFILE.TXT';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;input @1 Company $20. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/54795"&gt;@25&lt;/a&gt; State $2. @;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if State=' &amp;nbsp;' &amp;nbsp;then input @30 Year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else input @30 City Year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;input NumEmployees;&lt;BR /&gt;run;&amp;nbsp;&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;How many raw data records are read during each iteration of the DATA step?&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;The Answer is 2.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Why? Isn't a record, one line of data with one or many observations? So Every iteration, reads only one line to input into a SAS dataset. Is my thinking not correct?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My thinking:&lt;/DIV&gt;&lt;DIV&gt;Record 1 = Obs1 Obs2 Obs3&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Record 2&amp;nbsp;= Obs4 Obs5 Obs6&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Dec 2015 21:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241161#M44653</guid>
      <dc:creator>Durlov</dc:creator>
      <dc:date>2015-12-29T21:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241167#M44656</link>
      <description>&lt;P&gt;This data step implements the case where two records from file datafile.txt are read to form a single observation in dataset worm.info.&lt;/P&gt;
&lt;P&gt;An input statement with a trailling '@' stays on the same line so hat the next input within the same iteration continues at the same position.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 21:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241167#M44656</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-29T21:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241172#M44661</link>
      <description>&lt;P&gt;Oh, I see what you're saying. The first record being read is the one with the&amp;nbsp;@ and the second is the next record in the data set. Is that correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to note, for the very first iteration all the data would be from the same record, so that would be one record, right?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 22:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241172#M44661</guid>
      <dc:creator>Durlov</dc:creator>
      <dc:date>2015-12-29T22:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241198#M44676</link>
      <description>&lt;P&gt;The first line read would contain either&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Company&lt;/STRONG&gt; &lt;EM&gt;Blank&lt;/EM&gt; &lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Company State City Year&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second line read would contain&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NumEmployees&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output dataset will thus contain all those fields, with missing values for State and City for some observations.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 05:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241198#M44676</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-30T05:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241216#M44685</link>
      <description>&lt;P&gt;You will execute&amp;nbsp;three input statements (there are actually four in the code but two are in the same IF/THEN/ELSE block so only one of the will execute.) &amp;nbsp;But the first one uses the trailing @ that will keep the same line of input. So the second INPUT that executes reads from the same input line as the first INPUT statement used. &amp;nbsp;You then read a second line of input with the final INPUT statement.&amp;nbsp; That is why each iteration of the data step reads two lines of the input data file. &amp;nbsp;So if your data file has 20 lines your resulting SAS dataset will have 10 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only wrinkle that could happen to change this would be if some of&amp;nbsp;the requested fields are not populated. &amp;nbsp;This could cause some of the INPUT statements to go to the next line to look for values of STATE, CITY or YEAR. You can add the TRUNCOVER option to the INFILE statement to prevent that.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 13:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241216#M44685</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-12-30T13:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241223#M44689</link>
      <description>&lt;P&gt;So, the data set would be set up as follows?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Record 1: Company State City Year&lt;/P&gt;&lt;P&gt;Record 2: NumEmployees&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Record 3: CompanyObs1 StateObs1 CityObs1 Year&lt;SPAN&gt;Obs1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Record 4: NumEmployees&lt;SPAN&gt;Obs1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Record 5: CompanyObs2&amp;nbsp;StateObs2 CityObs2 Year&lt;SPAN&gt;Obs2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Record 6: NumEmployees&lt;SPAN&gt;Obs2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm understanding from your explanations, that the only reason one would use 2 "input" statements (note, I'm skipping over the IF/ELSE statements) is if the data is split up as above. Is that correct? I highlighted the "input" statements I'm talking about below.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;data WORM.INFO;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;infile 'DATAFILE.TXT';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;input&lt;/STRONG&gt; @1 Company $20. &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/54795" target="_blank"&gt;@25&lt;/A&gt; State $2. @;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if State=' &amp;nbsp;' &amp;nbsp;then input @30 Year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else input @30 City Year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;input&lt;/STRONG&gt; NumEmployees;&lt;BR /&gt;run;&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 15:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241223#M44689</guid>
      <dc:creator>Durlov</dc:creator>
      <dc:date>2015-12-30T15:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241230#M44692</link>
      <description>&lt;P&gt;The best way to understand SAS programming is to play with small examples, such as :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INFO;
input @1 Company $20. @25 State $2. @;
if State='  '  then input @30 Year;
else input @30 City Year;
input NumEmployees;
datalines;
Some Place Inc.         CA   123456     2012
10
Nowhere Ltd                             2013
100
Every Where Corp.       VT   654321     2014
1000
;

proc print data=info noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's only when I tried this that I realized that City was defined as a number.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 16:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241230#M44692</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-30T16:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Practice Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241231#M44693</link>
      <description>Great! Thanks much for you're help. I usually, try to do the examples in SAS, but don't have access to it at work. So need to run them after I get home.</description>
      <pubDate>Wed, 30 Dec 2015 16:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Practice-Question/m-p/241231#M44693</guid>
      <dc:creator>Durlov</dc:creator>
      <dc:date>2015-12-30T16:28:37Z</dc:date>
    </item>
  </channel>
</rss>

