datalines into an existing dataset

Accepted Solution Solved
Reply
Valued Guide
Posts: 860
Accepted Solution

datalines into an existing dataset

This is a beginner's questions.  I'm wondering what the syntax error in the following is:

data work.ds2;

   array Response{*} a b c d e;

run;

data ds2;

  set ds2;

  input;

  datalines;

1 2 3 4 5

;

run;

I don't know why the 1 2 3 4 5 isn't entering in the the original table.  I tried it with/without input; with no luck.  Thanks for any help.


Accepted Solutions
Solution
‎07-25-2012 03:21 PM
Contributor
Posts: 52

Re: datalines into an existing dataset

Posted in reply to Steelers_In_DC

The specific problem is that you are using a null input statement. That form of an input statement does not create any variables. If you want to read in the variables, you have to specify the list of variables, using the statement, say, INPUT A B C D E;

A different problem is that you don't need two data steps; in fact the first one is basically irrelevant. The first data step does set up five variables, a through e, with missing values and creates a dataset. The second data step replaces the first dataset. Try the following:

data work.ds2 (drop=i);

   array response {*} a b c d e;

   do i = 1 to dim(response);

      response{i} = i;

   end;

run;

Now open up the dataset and look at the values. Then close it and run the next step:

data ds2;

   set ds2;

   input a b c d e;

   datalines;

6 7 8 9 10

;

run;

Note that there is only one record. Open up the data set. You will now have different values in those variables.

I hope this helps.

View solution in original post


All Replies
PROC Star
Posts: 7,474

Re: datalines into an existing dataset

Posted in reply to Steelers_In_DC

Not sure what you are trying to do.  The first datastep, where you declare an array, probably isn't necessary.

If you do need it, and are only trying to add one record with those five values, you probably only need to change the third line of the second program.  i.e., instead of input;   use input a b c d e;

HTH,

Art

Solution
‎07-25-2012 03:21 PM
Contributor
Posts: 52

Re: datalines into an existing dataset

Posted in reply to Steelers_In_DC

The specific problem is that you are using a null input statement. That form of an input statement does not create any variables. If you want to read in the variables, you have to specify the list of variables, using the statement, say, INPUT A B C D E;

A different problem is that you don't need two data steps; in fact the first one is basically irrelevant. The first data step does set up five variables, a through e, with missing values and creates a dataset. The second data step replaces the first dataset. Try the following:

data work.ds2 (drop=i);

   array response {*} a b c d e;

   do i = 1 to dim(response);

      response{i} = i;

   end;

run;

Now open up the dataset and look at the values. Then close it and run the next step:

data ds2;

   set ds2;

   input a b c d e;

   datalines;

6 7 8 9 10

;

run;

Note that there is only one record. Open up the data set. You will now have different values in those variables.

I hope this helps.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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