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

Hi,

 I have ad a data with observations as:

2160048011442.293800000 -87.951300000

 

i want to separate each observation into different variable colums

2#1#60048#0#11#4#42.293800000 #-87.951300000# (DATA do NOT have this "#"). I cannot put this # for each observation as there are millions of observations.

 

var 1
1-1 (position)
1 (length)
var2
2-2
1
var3
3-7
5
var4
8-8
1
var5
9-10
2
var6
11-11
1
var7
12-24
13.7
var8
25-37
13.7

 

how should I code?

I appreciate your input.

Thanks

 

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You likely have what's known as a fixed width file. 


Assuming your record layout as posted, try the following, tested code:

 

data have;
infile cards;
input  var1  1-1
       var2  2-2  
       var3  3-7
       var4  8-8
       var5  9-10
       var6  11-11
       var7  12-24
       var8  25-37;
cards;
2160048011442.293800000 -87.951300000
;;;;
run;

 


@runn wrote:

Hi,

 I have ad a data with observations as:

2160048011442.293800000 -87.951300000

 

i want to separate each observation into different variable colums

2#1#60048#0#11#4#42.293800000 #-87.951300000# (DATA do NOT have this "#"). I cannot put this # for each observation as there are millions of observations.

 

var 1
1-1 (position)
1 (length)
var2
2-2
1
var3
3-7
5
var4
8-8
1
var5
9-10
2
var6
11-11
1
var7
12-24
13.7
var8
25-37
13.7

 

how should I code?

I appreciate your input.

Thanks

 

run;



 

View solution in original post

3 REPLIES 3
Reeza
Super User

You likely have what's known as a fixed width file. 


Assuming your record layout as posted, try the following, tested code:

 

data have;
infile cards;
input  var1  1-1
       var2  2-2  
       var3  3-7
       var4  8-8
       var5  9-10
       var6  11-11
       var7  12-24
       var8  25-37;
cards;
2160048011442.293800000 -87.951300000
;;;;
run;

 


@runn wrote:

Hi,

 I have ad a data with observations as:

2160048011442.293800000 -87.951300000

 

i want to separate each observation into different variable colums

2#1#60048#0#11#4#42.293800000 #-87.951300000# (DATA do NOT have this "#"). I cannot put this # for each observation as there are millions of observations.

 

var 1
1-1 (position)
1 (length)
var2
2-2
1
var3
3-7
5
var4
8-8
1
var5
9-10
2
var6
11-11
1
var7
12-24
13.7
var8
25-37
13.7

 

how should I code?

I appreciate your input.

Thanks

 

run;



 

runn
Calcite | Level 5

I appreciate Reeza but I have 1.5 million observation. It makes SAS slower if I past all the observations as a dateline in the code.

 

There should be some other way as well.

 

Thanks.

Tom
Super User Tom
Super User

@runn wrote:

I appreciate Reeza but I have 1.5 million observation. It makes SAS slower if I past all the observations as a dateline in the code.

 

There should be some other way as well.

 

Thanks.


Why would you post the data lines in the code????

If you have the data in a text file then use a INFILE statement to tell SAS where to read the data.

Reeza's example is just to show you how your INPUT statement should look based on your description of your record layout.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 797 views
  • 2 likes
  • 3 in conversation