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;
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;
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;
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.
@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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.