<?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 Reading raw data from a text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/484159#M125658</link>
    <description>&lt;P&gt;A raw data file is listed below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RANCH,1250,2,1,Sheppard Avenue,"$64,000"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPLIT,1190,1,1,Rand Street,"$65,850"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CONDO,1400,2,1.5,Market Street,"80,050"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TWOSTORY,1810,4,3,Garris Street,"$107,250"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RANCH,1500,3,3,Kemble Avenue,"$86,650"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPLIT,1615,4,3,West Drive,"94,450"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPLIT,1305,3,1.5,Graham Avenue,"$73,650"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following SAS program is submitted using the raw data file as input:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.condo_ranch;&lt;/P&gt;&lt;P&gt;&amp;nbsp;infile 'file-specification' dsd;&lt;/P&gt;&lt;P&gt;input style $ @;&lt;/P&gt;&lt;P&gt;if style = 'CONDO' or style = 'RANCH';&lt;/P&gt;&lt;P&gt;input sqfeet bedrooms baths street $ price : dollar10.;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you please help me out in this case , why only 3 observations are in output data set ,&amp;nbsp;?&amp;nbsp;in input&amp;nbsp;there are 5 variables so there should be 5 observation&lt;/P&gt;</description>
    <pubDate>Sun, 05 Aug 2018 15:08:44 GMT</pubDate>
    <dc:creator>sanyam13</dc:creator>
    <dc:date>2018-08-05T15:08:44Z</dc:date>
    <item>
      <title>Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/484159#M125658</link>
      <description>&lt;P&gt;A raw data file is listed below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RANCH,1250,2,1,Sheppard Avenue,"$64,000"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPLIT,1190,1,1,Rand Street,"$65,850"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CONDO,1400,2,1.5,Market Street,"80,050"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TWOSTORY,1810,4,3,Garris Street,"$107,250"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RANCH,1500,3,3,Kemble Avenue,"$86,650"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPLIT,1615,4,3,West Drive,"94,450"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SPLIT,1305,3,1.5,Graham Avenue,"$73,650"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following SAS program is submitted using the raw data file as input:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.condo_ranch;&lt;/P&gt;&lt;P&gt;&amp;nbsp;infile 'file-specification' dsd;&lt;/P&gt;&lt;P&gt;input style $ @;&lt;/P&gt;&lt;P&gt;if style = 'CONDO' or style = 'RANCH';&lt;/P&gt;&lt;P&gt;input sqfeet bedrooms baths street $ price : dollar10.;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you please help me out in this case , why only 3 observations are in output data set ,&amp;nbsp;?&amp;nbsp;in input&amp;nbsp;there are 5 variables so there should be 5 observation&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 15:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/484159#M125658</guid>
      <dc:creator>sanyam13</dc:creator>
      <dc:date>2018-08-05T15:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/484163#M125660</link>
      <description>Hi:&lt;BR /&gt;  If you look at the data, you'll see that only 3 rows meet your subsetting IF condition. Read about the subsetting IF in the documentation. BEFORE the second INPUT statement, you have this:&lt;BR /&gt;if style='CONDO' or style='RANCH';&lt;BR /&gt;&lt;BR /&gt;What did you think this statement was doing? Any data row that meets the criteria in the IF will go forward in the logic to the second INPUT statement. Any data row that does NOT meet the condition does NOT get parsed or get output. &lt;BR /&gt;&lt;BR /&gt;  Only the rows that meet the subsetting IF condition get parsed by the second INPUT statement and get OUTPUT by the implied output at the end of the DATA step program.&lt;BR /&gt;  &lt;BR /&gt;Cynthia</description>
      <pubDate>Sun, 05 Aug 2018 15:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/484163#M125660</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-08-05T15:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932530#M366847</link>
      <description>&lt;P&gt;i think the "if style" statement must have a "then" keyword at the end as i suspect you have got this question from somewhere on the web dumps&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 13:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932530#M366847</guid>
      <dc:creator>Nipun22</dc:creator>
      <dc:date>2024-06-15T13:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932532#M366848</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420483"&gt;@Nipun22&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i think the "if style" statement must have a "then" keyword at the end as i suspect you have got this question from somewhere on the web dumps&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code is valid. What you see in it is a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank" rel="noopener"&gt;Subsetting IF&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 14:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932532#M366848</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-15T14:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932533#M366849</link>
      <description>&lt;P&gt;As others have said the reason you only get 3 observations from 5 lines in the text file is because the subsetting IF&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if style = 'CONDO' or style = 'RANCH';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is only allowing 3 of the data step iterations to get to the implied OUTPUT at the end of the step and be written to the output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other cases might see a mismatch between the number of lines read and the number of observations written for code like that because of the use of the default FLOWOVER option on the INFILE statement.&amp;nbsp; IN that case any line that did not have the full number of fields (or had a missing value for the last field) would cause the INPUT statement to go to the next line to look for a values to satisfy all of the variables being read.&amp;nbsp; It would be safer to include the TRUNCOVER option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile 'file-specification' dsd truncover;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: You almost never want the older MISSOVER option since that one will cause trouble if your INPUT statement is using FORMATTED MODE input and there are not enough characters on the line to fully meet the width the informat needs.&amp;nbsp; In that case MISSOVER will ignore those short values at the end of the line.&amp;nbsp; By using TRUNCOVER will allow the INPUT statement to read them so your result better matches the source text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 14:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932533#M366849</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-15T14:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932537#M366850</link>
      <description>Hi Tom,&lt;BR /&gt;actually i wanted to know if we place a "then" keyword at the end of the "if style" statement then the output dataset would have 7 observations. can you tell me why?</description>
      <pubDate>Sat, 15 Jun 2024 15:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932537#M366850</guid>
      <dc:creator>Nipun22</dc:creator>
      <dc:date>2024-06-15T15:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading raw data from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932538#M366851</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420483"&gt;@Nipun22&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Tom,&lt;BR /&gt;actually i wanted to know if we place a "then" keyword at the end of the "if style" statement then the output dataset would have 7 observations. can you tell me why?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Adding THEN will change these two statements like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;lt;condition&amp;gt;;
&amp;lt;statement&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;into two statements like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;lt;condition&amp;gt; then &amp;lt;statement1&amp;gt;;
&amp;lt;statement2&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So when the IF/THEN statement basically does nothing since when it the condition is FALSE it moves to the next statement and when it is TRUE it executes an empty statement before moving to the next statement.&amp;nbsp; The second statement (in your case the INPUT statement) executes in either case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the original program when the condition in the subsetting IF statement is FALSE it will immediately stop the current data step iteration. Which will mean that only the cases where the condition is true will make it to the end of the data step code where SAS will execute the implied OUTPUT it adds to any data step that does not have an explicit OUTPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you also remove the semicolon you end up with just one statement in this form:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;lt;condition&amp;gt; then &amp;lt;statement&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then in your case it will cause the other 6 variables on the line to only be populated for 3 of the 7 lines of input text.&amp;nbsp; The other observations will have missing values for those variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jun 2024 15:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-raw-data-from-a-text-file/m-p/932538#M366851</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-15T15:51:26Z</dc:date>
    </item>
  </channel>
</rss>

