<?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: Reading data file but only bring in numeric values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9063#M533</link>
    <description>For diagnostic review, suggest you add a PUTLOG _ALL_;  statement to your program, you would see that the _ERROR_ variable is set to 1 when you cannot perform the input.  Then you can perform some other/additional task with a DO/END code piece in your DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Fri, 23 Apr 2010 19:59:39 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-04-23T19:59:39Z</dc:date>
    <item>
      <title>Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9060#M530</link>
      <description>Hello everyone,&lt;BR /&gt;
I have a file that looks like this&lt;BR /&gt;
===========================================================&lt;BR /&gt;
Test Data&lt;BR /&gt;
&lt;BR /&gt;
Date 3/12/09&lt;BR /&gt;
&lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182,&lt;BR /&gt;
27666, 27532, 25707, 27494&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Date 3/16/09&lt;BR /&gt;
----------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Received 3/14/09&lt;BR /&gt;
&lt;BR /&gt;
73307,65046,45434,85498,85704,86975,18305,18754,20098,20990,&lt;BR /&gt;
72034,72389,43949,74336,75148,95609,27495,27686,27689,28710,&lt;BR /&gt;
89108,69253,59294,69588,81358,91629,31675,31714,31759,33012,&lt;BR /&gt;
43141,53205&lt;BR /&gt;
&lt;BR /&gt;
Need to update&lt;BR /&gt;
===========================================================&lt;BR /&gt;
&lt;BR /&gt;
How can I just read in the numeric rows and then have them parsed out into a row per number?&lt;BR /&gt;
&lt;BR /&gt;
This is very urgent so any help would be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Thank you</description>
      <pubDate>Fri, 23 Apr 2010 14:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9060#M530</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2010-04-23T14:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9061#M531</link>
      <description>Hi:&lt;BR /&gt;
  I don't understand...does your data file contain&lt;BR /&gt;
======================================= and&lt;BR /&gt;
-----------------------------------------------------------------------&lt;BR /&gt;
 &lt;BR /&gt;
and all the white space, or were those separate records that you were trying to indicate???&lt;BR /&gt;
&lt;BR /&gt;
What about Date 3/12/09 and Date 3/16/09?? Are those IN the file or your descriptions of the data?? Are they separate files? What about the Received 3/14/09??? Again, part of the data or not??&lt;BR /&gt;
&lt;BR /&gt;
Also, about the data...in your file, is there really a line break between 33182 and 27666 for example, or if you open the file with Notepad, do you see this. &lt;BR /&gt;
[pre]&lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182, 27666, 27532, 25707, 27494&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
or is there a line break or carriage return at the end of 33182, as shown below:&lt;BR /&gt;
                &lt;BR /&gt;
[pre]&lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182,&lt;BR /&gt;
27666, 27532, 25707, 27494&lt;BR /&gt;
[/pre]  &lt;BR /&gt;
  &lt;BR /&gt;
You say you want one row per number  -- by which I think you mean:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 97101&lt;BR /&gt;
 97440&lt;BR /&gt;
 67431&lt;BR /&gt;
 55798&lt;BR /&gt;
 42905&lt;BR /&gt;
 22590&lt;BR /&gt;
 31634&lt;BR /&gt;
 19139&lt;BR /&gt;
 20920&lt;BR /&gt;
 33182&lt;BR /&gt;
 27666&lt;BR /&gt;
 27532&lt;BR /&gt;
 25707&lt;BR /&gt;
 27494&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
What would you call that variable Date_3_12_09??? or just NUM or maybe NUMVAR????  Would you want each observation to consist of only one variable or should each observation look like this (partial output):&lt;BR /&gt;
[pre]&lt;BR /&gt;
Date       Num&lt;BR /&gt;
3/12/09   97101&lt;BR /&gt;
3/12/09   97440&lt;BR /&gt;
3/12/09   67431&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
You say that you have a "file" is this an ASCII text file (a file that you can open using Notepad)? Is this data in an Excel spreadsheet??&lt;BR /&gt;
&lt;BR /&gt;
If you have a truly urgent need for help, then you should open a track with Tech Support. In order to help you here, folks really need to see the actual layout of the file you will be reading (with ------ and =====) if those are in the file, but without those cosmetics if they are not in the file.&lt;BR /&gt;
&lt;BR /&gt;
Can you show us any code that you have already tried??? To learn how to post code and data, refer to this previous forum posting:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609毙" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609毙&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 23 Apr 2010 15:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9061#M531</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-23T15:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9062#M532</link>
      <description>Cynthia,&lt;BR /&gt;
Thank you for your quick reply.  I do apologize for not being clearer.&lt;BR /&gt;
&lt;BR /&gt;
This is a text file that can be viewed in notepad.  It is generated by someone else.  My task is to find the rows that start with a numeric character and then pull that row and all following rows till I run out of data then continue on till I find another row starting with numeric data then pull that data out.  I don't need to keep any text or dates.&lt;BR /&gt;
This is exactly what is in the data file. "Need to update" is the last line of the file.&lt;BR /&gt;
&lt;BR /&gt;
Test Data&lt;BR /&gt;
&lt;BR /&gt;
Date 3/12/09&lt;BR /&gt;
&lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182,&lt;BR /&gt;
27666, 27532, 25707, 27494&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Date 3/16/09&lt;BR /&gt;
----------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
Received 3/14/09&lt;BR /&gt;
&lt;BR /&gt;
73307,65046,45434,85498,85704,86975,18305,18754,20098,20990,&lt;BR /&gt;
72034,72389,43949,74336,75148,95609,27495,27686,27689,28710,&lt;BR /&gt;
89108,69253,59294,69588,81358,91629,31675,31714,31759,33012,&lt;BR /&gt;
43141,53205&lt;BR /&gt;
&lt;BR /&gt;
Need to update&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
This is the code I have so far but this is just testing against a file with just 2 rows of &lt;BR /&gt;
&lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182,&lt;BR /&gt;
27666, 27532, 25707, 27494&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename indata "c:\temp\test.txt";&lt;BR /&gt;
data multi ;&lt;BR /&gt;
	infile indata dlm=','  ;	&lt;BR /&gt;
	input num @@ ;		&lt;BR /&gt;
run ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
I wanted to see how I can parse out the data.  I got working but I don't know how to check which row is a numeric row or a character row.&lt;BR /&gt;
&lt;BR /&gt;
Thank you</description>
      <pubDate>Fri, 23 Apr 2010 16:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9062#M532</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2010-04-23T16:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9063#M533</link>
      <description>For diagnostic review, suggest you add a PUTLOG _ALL_;  statement to your program, you would see that the _ERROR_ variable is set to 1 when you cannot perform the input.  Then you can perform some other/additional task with a DO/END code piece in your DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 23 Apr 2010 19:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9063#M533</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-04-23T19:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9064#M534</link>
      <description>RXPARSE may help you scan a record to see if it has any character values.  Here's an example although I had to do two parses to get all the non-numeric rows flagged.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
	infile 'c:\temp\testfile.txt' dlm=',';&lt;BR /&gt;
	input string :$100. @@;&lt;BR /&gt;
	rx=rxparse("$A");&lt;BR /&gt;
	rx2=rxparse("$'-'");&lt;BR /&gt;
	istext = rxmatch(rx,string) or rxmatch(rx2,string);&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]

Message was edited by: 1162</description>
      <pubDate>Fri, 23 Apr 2010 20:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9064#M534</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2010-04-23T20:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9065#M535</link>
      <description>Hi:&lt;BR /&gt;
  I'm sure there's a more elegant way to read this using double trailing at signs (@@) ,but I like this method because it would also give me the opportunity to parse out the dates if I needed them.&lt;BR /&gt;
 &lt;BR /&gt;
First, I put -exactly- these lines into a file, called &lt;B&gt;c:\temp\mixed_data.txt&lt;/B&gt;&lt;BR /&gt;
[pre]&lt;BR /&gt;
Test Data&lt;BR /&gt;
                           &lt;BR /&gt;
Date 3/12/09&lt;BR /&gt;
                                     &lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182,&lt;BR /&gt;
27666, 27532, 25707, 27494&lt;BR /&gt;
                     &lt;BR /&gt;
                             &lt;BR /&gt;
Date 3/16/09&lt;BR /&gt;
----------------------------------------------&lt;BR /&gt;
                                 &lt;BR /&gt;
Received 3/14/09&lt;BR /&gt;
                             &lt;BR /&gt;
73307,65046,45434,85498,85704,86975,18305,18754,20098,20990,&lt;BR /&gt;
72034,72389,43949,74336,75148,95609,27495,27686,27689,28710,&lt;BR /&gt;
89108,69253,59294,69588,81358,91629,31675,31714,31759,33012,&lt;BR /&gt;
43141,53205&lt;BR /&gt;
                               &lt;BR /&gt;
Need to update&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                          &lt;BR /&gt;
Then I use this program to read in 1 line of the file at a time. The INPUT statement uses $VARYING with a length variable in order to read the whole text line and treat each line as a separate entity. (The length variable, LG, comes from using the LENGTH= option on the INFILE statement.) Using $VARYING allows me to read variable length lines --  short lines and long lines without needing to know the exact length of each data line.&lt;BR /&gt;
    &lt;BR /&gt;
 I test the first 4 bytes of the line to see whether it is in this list: Date, Need, Rece, Test or ---- or 4 blanks. I also test to see if the line is "empty" -- basically a carriage return without anything else on the line. If the dataline falls into these categories, it is just deleted and control returns to the top of the DATA step to read the next line.&lt;BR /&gt;
&lt;BR /&gt;
When a dataline doesn't meet any of these conditions, it must be a line with numbers, so the COUNTC function finds out how many commas there are in the line and then the DO loop loops through the line and parses out each number into a character variable. Then a numeric variable is created by using the INPUT function (to turn a character variable into a numeric variable. Each parsed number is output -- so for example, the first data line with numbers contains 10 numbers and so 10 observations are created and the second data line with numbers contains 4 numbers and so 4 observations are created.&lt;BR /&gt;
&lt;BR /&gt;
Once you understand what the program is doing, I would recommend uncommenting the DROP statement to get rid of unwanted variables. And, of course, you can  tweak the program, as needed if you find that there are other stray text lines in the file.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
options ls=120;&lt;BR /&gt;
                                                &lt;BR /&gt;
data readmixed;&lt;BR /&gt;
length line $100;&lt;BR /&gt;
** once you understand what program is doing, then drop unneeded variables;&lt;BR /&gt;
** DROP line i charvar orig_line_num;&lt;BR /&gt;
  infile 'c:\temp\mixed_data.txt' length=lg;&lt;BR /&gt;
  input @1 line $varying. lg ;&lt;BR /&gt;
  orig_line_num = _n_;        &lt;BR /&gt;
  ** lg will equal 0 when there is an empty line in the file without any space characters;&lt;BR /&gt;
  if substr(line,1,4) in ('Date', 'Test', 'Rece', 'Need', '----', '    ') or lg=0 then do;&lt;BR /&gt;
     delete; &lt;BR /&gt;
     return; &lt;BR /&gt;
  end;&lt;BR /&gt;
  else do;&lt;BR /&gt;
     num_comma = countc(line,',');&lt;BR /&gt;
     ** add 1 because sometimes there is NOT a comma at the end of a line of data;&lt;BR /&gt;
     ** if you do an extra scan and there is nothing found, then charvar will be missing or blank;&lt;BR /&gt;
     ** and the IF statement will keep that last value from being output.;&lt;BR /&gt;
     do i = 1 to num_comma + 1;&lt;BR /&gt;
        charvar = scan(line,i,',');&lt;BR /&gt;
        numvar = input(charvar,best12.);&lt;BR /&gt;
        if charvar ne ' ' then output;&lt;BR /&gt;
     end;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                          &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=readmixed;&lt;BR /&gt;
  title 'Output Data Set';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 23 Apr 2010 21:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9065#M535</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-23T21:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9066#M536</link>
      <description>*keep it simple&lt;BR /&gt;
 If a line starts with a number, output each number from that line, until there are no more numbers on the line[pre]data numbers  ;&lt;BR /&gt;
  infile datalines4 dsd truncover; *comma delimiter by default ;&lt;BR /&gt;
                           *get first data item of record/buffer as number ; &lt;BR /&gt;
  input number ?? @ ;      *??=avoid invalid data messages, @=hold this buffer ;&lt;BR /&gt;
  do while( number ne . ); *do not output from record when non-numeric is read ;&lt;BR /&gt;
     output ;&lt;BR /&gt;
     input number ?? @ ;  * get next number and hold buffer ;&lt;BR /&gt;
  end ;&lt;BR /&gt;
* with a single trailing @, the infile buffer is released as data step iterates ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Test Data&lt;BR /&gt;
 &lt;BR /&gt;
Date 3/12/09&lt;BR /&gt;
 &lt;BR /&gt;
97101, 97440, 67431, 55798, 42905, 22590, 31634, 19139, 20920, 33182,&lt;BR /&gt;
27666, 27532, 25707, 27494&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
Date 3/16/09&lt;BR /&gt;
----------------------------------------------&lt;BR /&gt;
 &lt;BR /&gt;
Received 3/14/09&lt;BR /&gt;
 &lt;BR /&gt;
73307,65046,45434,85498,85704,86975,18305,18754,20098,20990,&lt;BR /&gt;
72034,72389,43949,74336,75148,95609,27495,27686,27689,28710,&lt;BR /&gt;
89108,69253,59294,69588,81358,91629,31675,31714,31759,33012,&lt;BR /&gt;
43141,53205&lt;BR /&gt;
 &lt;BR /&gt;
Need to update&lt;BR /&gt;
;;;;&lt;BR /&gt;
 &lt;BR /&gt;
 [/pre]

truncover  added to infile  &amp;gt;&amp;gt;&amp;gt; Message was edited by: Peter.C</description>
      <pubDate>Mon, 26 Apr 2010 08:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9066#M536</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-04-26T08:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9067#M537</link>
      <description>Peter,&lt;BR /&gt;
Your solution seems to be the cleanest for what I need it for.  &lt;BR /&gt;
&lt;BR /&gt;
Thank you and to everyone else's suggestions I pick up a lot of info from everyone posts. &lt;BR /&gt;
&lt;BR /&gt;
I do appreciate everyone's help.</description>
      <pubDate>Mon, 26 Apr 2010 12:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9067#M537</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2010-04-26T12:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9068#M538</link>
      <description>Peter:&lt;BR /&gt;
  Very elegant! &lt;BR /&gt;
&lt;BR /&gt;
  If the data had come from some of my former customers, however, they would have been back a week later and said, "Hey, you know that file of numbers you gave us, it would be really swell if you could give us the dates that were in that original text file, too."  That's how I got into the habit of coding in anticipation of what their next request was going to be. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 26 Apr 2010 20:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9068#M538</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-26T20:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data file but only bring in numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9069#M539</link>
      <description>that should require very little more&lt;BR /&gt;
Before the Datalines  statement, insert[pre]&lt;BR /&gt;
  if _infile_ =: 'Date' ;&lt;BR /&gt;
  input @6 set_date : mmddyy. ;&lt;BR /&gt;
  retain   set_date ;&lt;BR /&gt;
  attrib   set_date format= date9. ; &lt;BR /&gt;
[/pre]

datalines4 statement should have no 4       Message was edited by: Peter.C</description>
      <pubDate>Mon, 26 Apr 2010 21:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-data-file-but-only-bring-in-numeric-values/m-p/9069#M539</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-04-26T21:45:48Z</dc:date>
    </item>
  </channel>
</rss>

