BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JUMMY
Obsidian | Level 7

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;

 

ballardw
Super User

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.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 977 views
  • 0 likes
  • 3 in conversation