BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wutao9999
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User
Can you attach a sample of your text file and post expected output?
wutao9999
Obsidian | Level 7

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.

Reeza
Super User

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;

 

 

wutao9999
Obsidian | Level 7

The post does not accept .dat format.  Sorry for the trouble.  Your help is greatly appricated.

 

Tao

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 4 replies
  • 1479 views
  • 0 likes
  • 2 in conversation