Help using Base SAS procedures

Only read numeric values from a file.

Reply
N/A
Posts: 0

Only read numeric values from a file.

Hello:

I have a data file like the following stored as a .csv file. I would like to only read the numbers out of it. Right now I am using the following code, it reads in the data file, and I would like to delete every other row (eg,row no. 1, 3, 5, 7, ..), or let's say the rows starting with letters, and only output the numbers. How should I do this?

Thanks in advance



filename datain
'...matrix.csv' LRECL=500;
data matrix;
infile datain DELIMITER=',';
input A $ B $ C $ D $ E $ F $;
run;



TH12,|,TH,5,TH12,|,TH
-7.64E-03,6.06E-01,9.98E-03,2.11E-02,3.96E-01,2.08E+00,1.38E-01

TH15,|,TH,2,TH15,|,TH
4.12E-04,-1.93E-02,-1.74E-03,-1.14E-02,6.39E-01,9.71E-03,2.08E-02

TH15,|,TH10,TH15,|,TH12,TH15
1.75E-01,9.52E-01,9.07E-01,2.17E-03,5.40E-06,-1.05E-04,1.37E-04

OM1213,|,OM0506,OM1213,|,OM0606,OM1213
2.91E-07,-1.48E-05,-3.88E-07,-3.53E-08,-1.07E-07,8.66E-08,-8.50E-08
Respected Advisor
Posts: 3,777

Re: Only read numeric values from a file.

Use the / pointer control.

[pre]
data matrix;
infile cards dsd;
input / v1-v7;
cards;
TH12,|,TH,5,TH12,|,TH
-7.64E-03,6.06E-01,9.98E-03,2.11E-02,3.96E-01,2.08E+00,1.38E-01
TH15,|,TH,2,TH15,|,TH
4.12E-04,-1.93E-02,-1.74E-03,-1.14E-02,6.39E-01,9.71E-03,2.08E-02
TH15,|,TH10,TH15,|,TH12,TH15
1.75E-01,9.52E-01,9.07E-01,2.17E-03,5.40E-06,-1.05E-04,1.37E-04
OM1213,|,OM0506,OM1213,|,OM0606,OM1213
2.91E-07,-1.48E-05,-3.88E-07,-3.53E-08,-1.07E-07,8.66E-08,-8.50E-08
;;;;
run;
[/pre]
N/A
Posts: 0

Re: Only read numeric values from a file.

Hello,

you can check if the first character is a digit. the output statement in the syntax is necessary since the return statement contains an implicit OUTPUT statement:

[pre]
data x;
infile datalines dlm=',' truncover;
input @;
if anyalpha(substr(_infile_,1,1)) then return;
input A $ B $ C $ D $ E $ F $;
output;
datalines;
TH12,|,TH,5,TH12,|,TH
-7.64E-03,6.06E-01,9.98E-03,2.11E-02,3.96E-01,2.08E+00,1.38E-01
TH15,|,TH,2,TH15,|,TH
4.12E-04,-1.93E-02,-1.74E-03,-1.14E-02,6.39E-01,9.71E-03,2.08E-02
TH15,|,TH10,TH15,|,TH12,TH15
1.75E-01,9.52E-01,9.07E-01,2.17E-03,5.40E-06,-1.05E-04,1.37E-04
OM1213,|,OM0506,OM1213,|,OM0606,OM1213
2.91E-07,-1.48E-05,-3.88E-07,-3.53E-08,-1.07E-07,8.66E-08,-8.50E-08
;
[/pre]

Marius
Ask a Question
Discussion stats
  • 2 replies
  • 132 views
  • 0 likes
  • 2 in conversation