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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.