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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

6 REPLIES 6
mohamed_zaki
Barite | Level 11

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?

nkurek0
Calcite | Level 5

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.

Kurt_Bremser
Super User

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.

nkurek0
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1597 views
  • 2 likes
  • 4 in conversation