I want to read a series of coordinate into SAS dataset. There are three variables: AREA, X and Y. AREA is a character variable.
When there is only one value of AREA and coresponding (X,Y) coordinates, I can use the program:
data grid;
retain area;
if _n_=1 then input area :$1. @;
input x y @@;
datalines;
E 0 150 35 155 50 550
;
The result what I want:
AREA X Y
The 1st Row: E 0 150
The 2nd Row: E 35 155
The 3rd Row: E 50 550
But I cann't handle condition with multiple level of AREA:
data grid;
retain area;
if _n_=1 then input area :$1. @;
input x y @@;
datalines;
E 0 150 35 155 50 550
D 0 100 25 100 50 125 80 215 125 550
C 0 60 30 60 50 80 70 110 260 550
;
This program failed.
Another difficulty is there maybe 3, 4 or 5 coordinates for each level of AREA.
Please help, Rearrange datalines is allowed but I don't want it occupy too much row, because I am putting it into presentation.
If you never having missing values of X just read until you find a missing value.
data grid;
infile datalines truncover ;
input area $ @ ;
do rep=1 by 1 until(x=.);
input x y @ ;
if (rep=1) or (x ne .) then output;
end;
datalines;
E 0 150 35 155 50 550
D 0 100 25 100 50 125 80 215 125 550
C 0 60 30 60 50 80 70 110 260 550
;
If you might have missing values then just read until you read past the end of the line.
data grid;
infile datalines column=cc length=ll truncover ;
input area $ @ ;
do rep=1 by 1 until(cc>ll);
input x y @ ;
if (rep=1) or n(x,y) then output;
end;
datalines;
E 0 150 35 155 50 550
D 0 100 25 100 50 125 80 215 125 550
C 0 60 30 60 50 80 70 110 260 550
;
If you never having missing values of X just read until you find a missing value.
data grid;
infile datalines truncover ;
input area $ @ ;
do rep=1 by 1 until(x=.);
input x y @ ;
if (rep=1) or (x ne .) then output;
end;
datalines;
E 0 150 35 155 50 550
D 0 100 25 100 50 125 80 215 125 550
C 0 60 30 60 50 80 70 110 260 550
;
If you might have missing values then just read until you read past the end of the line.
data grid;
infile datalines column=cc length=ll truncover ;
input area $ @ ;
do rep=1 by 1 until(cc>ll);
input x y @ ;
if (rep=1) or n(x,y) then output;
end;
datalines;
E 0 150 35 155 50 550
D 0 100 25 100 50 125 80 215 125 550
C 0 60 30 60 50 80 70 110 260 550
;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.