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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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