How do I code this data to be read as one observation spanning over three lines?
This is what the data looks like.
Data pregnancy;
Infile '/home/u63556826/sasuser.v94/BASIC50.DAT' missover;
Input
#1 Woman 1-5 Gravage 18-19
BirthWT 50-52 /
GRHEIGHT 84-85
GRWEIGHT 86-88 /
;
run;
proc print data=pregnancy;
run;
If it's always 3 source lines that need to map into a single SAS observation then code similar to below should work.
data demo;
infile datalines truncover;
input
#1 Woman 1-5 Gravage 18-19 BirthWT 50-52
#2 someVar 9-15
#3 someOtherVar $1-20
;
datalines;
00001150200070750242704380517069207391136212115111383014030100010210164007220090517
62136133691701143081090101010484051999299110 990 01101101117100000000001-1-1-1-1-1-
10301-1-1-12
00001251800070755262915311589160618151410122115211042844040100010310174306420091631
631341406919411430810801020205850714021011201035001101101119200000000001-101-1-1-
102-101-1-1-12
;
First, administrative stuff: Pasting ANY text into the main message window is subject to the forum software reformatting the text, generally removing white space but other things occur depending on exact pasted stuff.
So if you want to show us text, open a text box using the </> icon above the main message window and paste the text there.
It will help if you can show us what you mean by " read as one observation spanning over three lines". It is possible to read multiple lines at a time as a single observation. But I do not see any thing from your description that tells us what value goes into what variable.
The / on the input statement is an instruction to advance to the next line. An example (and shows what a text box looks like)
data example;
input x 1-3 y 4-6
/ z 1-5 a 6
/ b 4-5 c 7-8 ;
datalines;
123456789
123456789
123456789
;
I tend to place the / on the input statement so it is a bit easier to follow the code as to what I expect to read.
If your data is fixed column, which is the only way I can interpret what I see so far, you will need to count out each column for the variable you want. OR find a document that has the information for which variables start where. If you have such and have a hard time reading the data then share that document with us.
If any of the - in the body of that stuff does not start a negative numeric value you will have to provide a character format to read the values.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.