Each observation under Y has four values. I tried the following:
data one;
input X Y;
datalines;
2.5 7.5 9.5 8.0 8.5
5.0 11.0 12.0 9.0 10.0
7.5 11.0 16.0 12.5 14.0
10.0 16.5 14.5 21.5 19.0
;
run;
How do I enter the following data below in SAS using datalines?
X Y
2.5 7.5 9.5 8.0 8.5
5.0 11.0 12.0 9.0 10.0
7.5 11.0 16.0 12.5 14.0
10.0 16.5 14.5 21.5 19.0
This does not seem like a smart way to store data. You can only define Y like this as a character variable like this
data one;
input X Y $20.;
infile datalines dlm=',';
datalines;
2.5,7.5 9.5 8.0 8.5
5.0,11.0 12.0 9.0 10.0
7.5,11.0 16.0 12.5 14.0
10.0,16.5 14.5 21.5 19.0
;
run;
A more proper way of defining the data would be as four numeric variable Y1-Y4 like this
data one;
input X Y1-Y4;
datalines;
2.5 7.5 9.5 8.0 8.5
5.0 11.0 12.0 9.0 10.0
7.5 11.0 16.0 12.5 14.0
10.0 16.5 14.5 21.5 19.0
;
run;
This does not seem like a smart way to store data. You can only define Y like this as a character variable like this
data one;
input X Y $20.;
infile datalines dlm=',';
datalines;
2.5,7.5 9.5 8.0 8.5
5.0,11.0 12.0 9.0 10.0
7.5,11.0 16.0 12.5 14.0
10.0,16.5 14.5 21.5 19.0
;
run;
A more proper way of defining the data would be as four numeric variable Y1-Y4 like this
data one;
input X Y1-Y4;
datalines;
2.5 7.5 9.5 8.0 8.5
5.0 11.0 12.0 9.0 10.0
7.5 11.0 16.0 12.5 14.0
10.0 16.5 14.5 21.5 19.0
;
run;
Or perhaps:
data one; input X @; do i= 1 to 4; input Y @; output; end; drop i; datalines; 2.5 7.5 9.5 8.0 8.5 5.0 11.0 12.0 9.0 10.0 7.5 11.0 16.0 12.5 14.0 10.0 16.5 14.5 21.5 19.0 ; run;
Which creates 4 pairs of x, y values with the same X.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.