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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
tish
Calcite | Level 5

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

2 REPLIES 2
art297
Opal | Level 21

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

tish
Calcite | Level 5

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1061 views
  • 0 likes
  • 3 in conversation