Write and run SAS programs in your web browser

I cannot figure out what is causing the error message in my input statement

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

I cannot figure out what is causing the error message in my input statement

Can someone please let me know what is wrong with my code or advise me on an appropriate website where I can get help?  I am a beginner with SAS and I am taking a SAS programming class.  I am receiving the following error message:

 

77         INPUT LOCATION $ 1 LENGTH 2;

            _____

            180

 

 ERROR 180-322: Statement is not valid or it is used out of proper order.

 

Here is my code:

 

%web_drop_table(WORK.IMPORT);

 

FILENAME REFFILE "/home/nkurek0/my_courses/pgross/mussels.xlsx" TERMSTR=CR;

 

PROC IMPORT DATAFILE=REFFILE

                DBMS=XLSX

                OUT=WORK.IMPORT;

                GETNAMES=YES;

RUN;

 

PROC CONTENTS DATA=WORK.IMPORT; RUN;

 

 

%web_open_table(WORK.IMPORT);

DATA MUSSELS; SET WORK.IMPORT;  RUN;

INPUT LOCATION $ 1 LENGTH 2; RUN;

PROC PRINT DATA=MUSSELS; RUN;

PROC SORT DATA=MUSSELS; BY LOCATION; RUN;

PROC UNIVARIATE DATA=MUSSELS; By LOCATION; RUN;

PROC ANOVA DATA=MUSSELS;

CLASS LOCATION; MODEL LENGTH = LOCATION; RUN;

 


Accepted Solutions
Solution
‎01-21-2016 02:30 AM
Esteemed Advisor
Posts: 6,698

Re: I cannot figure out what is causing the error message in my input statement

Ups. I see it in your code:

DATA MUSSELS; SET WORK.IMPORT;  RUN;
INPUT LOCATION $ 1 LENGTH 2; RUN;

The RUN; terminates the data step, and puts the INPUT statement outside of the context of the data step. This causes the ERROR message.

Omit the first RUN; to make the code syntactically correct.

Your code is still semantically wrong, though.

The INPUT statement is used to read data from external sources. In your step you already have a SAS dataset, so INPUT is not valid here (INPUT requires an INFILE or CARDS statement in the same data step).

I guess you only want to have the variables (columns) location and length present in your data set. For this, you use the KEEP statement.

 

Regarding programming style: you don't need to go all capitals; code is usually easier to read when capitals are used sparingly, or not at all.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Esteemed Advisor
Posts: 6,698

Re: I cannot figure out what is causing the error message in my input statement

Please also post lines 1-76 of your log. Most ERROR messages cannot be interpreted correctly without knowing what happened up to the moment the error occured.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 490

Re: I cannot figure out what is causing the error message in my input statement

[ Edited ]

DATA MUSSELS; SET WORK.IMPORT;  RUN;

INPUT LOCATION $ 1 LENGTH 2; RUN;

 


 

 

Your INPUT statment should be part of DATA step, which mean should be inside the DATA step. But this is not happening here it is out the DATA step. So you are getting this error.

 

What are you doing? What is the use of INPUT statment in your code?

New Contributor
Posts: 3

Re: I cannot figure out what is causing the error message in my input statement

Thank you for taking the time to respond to my question.  Another member of the SAS community already solved the issue.  It turns out that I was supposed to use a KEEP statement intsead of an INPUT statement.  Have a good day.

Solution
‎01-21-2016 02:30 AM
Esteemed Advisor
Posts: 6,698

Re: I cannot figure out what is causing the error message in my input statement

Ups. I see it in your code:

DATA MUSSELS; SET WORK.IMPORT;  RUN;
INPUT LOCATION $ 1 LENGTH 2; RUN;

The RUN; terminates the data step, and puts the INPUT statement outside of the context of the data step. This causes the ERROR message.

Omit the first RUN; to make the code syntactically correct.

Your code is still semantically wrong, though.

The INPUT statement is used to read data from external sources. In your step you already have a SAS dataset, so INPUT is not valid here (INPUT requires an INFILE or CARDS statement in the same data step).

I guess you only want to have the variables (columns) location and length present in your data set. For this, you use the KEEP statement.

 

Regarding programming style: you don't need to go all capitals; code is usually easier to read when capitals are used sparingly, or not at all.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: I cannot figure out what is causing the error message in my input statement

Thank you so much for your help!  I really appreciate it.  Have a good day.

Esteemed Advisor
Esteemed Advisor
Posts: 7,249

Re: I cannot figure out what is causing the error message in my input statement

Could I ask what the reasoning behind the code formatting is.  You appear to have used every trick to make the code unreadable - all upper case, no consitent spacing,no new lines between code lines, and wrapping code unnecesarily in macro code.  A simple re-format will make your code look and read better, and highlight to you where these kind of problems occur:

filename reffile "/home/nkurek0/my_courses/pgross/mussels.xlsx" termstr=cr;
 
proc import datafile=reffile
  dbms=xlsx
  out=work.import;
  getnames=yes;
run;
 
proc contents data=work.import; 
run;

/* What does this codeliine below do? */ 
%web_open_table(work.import);

data mussels;   
  set work.import;  
run;

/* This code line is the problem as not associated with anything */
  input location $ 1 length 2; run;

proc print data=mussels; 
run;

proc sort data=mussels; 
  by location; 
run;

proc univariate data=mussels; 
  by location; 
run;

proc anova data=mussels;
  class location; 
  model length = location; 
run;
☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 413 views
  • 1 like
  • 4 in conversation