I have some irregular data in .dat file such as like below.
I hope to search for a SAS code that can read the data sequentially, starting from 25, 6, then 6, then 1277, then 1.7, 31.4, 78.1, ....., etc.
Is there any easy way to do that?
25 6
6
1277
1.7 31.4 78.1 2.4
0.2 0.2 0.4 0.4 0.4 0.2 0.3 0.4 0.3 0.3 0.3 0.3 0.3 0.3 0.2 0.3 0.3 0.2 0.3 0.3 0.2 0.4 0.3 0.2 0.2
47 159 48 1 45 177 83 121 50 31 164 121 135 157 54 167 64
21 43 149 30 165 173 96 167
In the future, it helps if you attach the actual data file rather than word documents. When you attach a word document you're relying on me creating the file and then writing the code for you as well.
This code works, you may need to tweak the LRECL. Basically read in the entire line as a text field and then parse it out using the SCAN() function.
data want;
infile 'C:\_localdata\delete.txt' lrecl=5000;
input;
x=countw(_infile_);
do i=1 to x;
Num=scan(_infile_, i, " ");
output;
end;
drop i x;
run;
I have attached file with input data and expected output data. I have thousands of such files that have different length of such data, so it would be helpful if the code is not strict to a specific number of data. Appreciate your help.
In the future, it helps if you attach the actual data file rather than word documents. When you attach a word document you're relying on me creating the file and then writing the code for you as well.
This code works, you may need to tweak the LRECL. Basically read in the entire line as a text field and then parse it out using the SCAN() function.
data want;
infile 'C:\_localdata\delete.txt' lrecl=5000;
input;
x=countw(_infile_);
do i=1 to x;
Num=scan(_infile_, i, " ");
output;
end;
drop i x;
run;
The post does not accept .dat format. Sorry for the trouble. Your help is greatly appricated.
Tao
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.