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

Hello,

Would someone be able to help me fix this error code?

FILENAME REFFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';

PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=WORK.IMPORT;
    GETNAMES=YES;
RUN;

PROC CONTENTS DATA=WORK.IMPORT; RUN;

DATA WORK.IMPORT;
INFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';
observations = input(FRED_Graph_Observations, 10.); RUN;
b_int = input(B, 10.); RUN;


%web_open_table(WORK.IMPORT);
 
This returns
ERROR 180-322: Statement is not valid or it is used out of proper order.

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You should comment your steps, it helps to find logical issues in your process:

 

Your issue is with the data step. Since you've already read in the file you don't need to read it in again and you can't read Excel files with INFILE.I would really recommend using more descriptive data set names as well. You also have a RUN statement too early, it ends the data step when you still want to do calculations. 

 

DATA Import2;

set Import;

observations = input(FRED_Graph_Observations, 10.); 

b_int = input(B, 10.);

 RUN;

Ideally your program would look like the following, note the comments and I changed the items in red. Hopefully this works for you 🙂

*path to file to import into SAS;
FILENAME REFFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';

*Import Excel File;
PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=Fred_GDP;
    GETNAMES=YES;
RUN;

PROC CONTENTS DATA=FRED_GDP; RUN;

*convert variables to numbers;
data fred2;
set fred_gdp;

observations = input(FRED_Graph_Observations, 10.); *remove early RUN;
b_int = input(B, 10.); 

 RUN;


@profjustin wrote:

Hello,

Would someone be able to help me fix this error code?

FILENAME REFFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';

PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=WORK.IMPORT;
    GETNAMES=YES;
RUN;

PROC CONTENTS DATA=WORK.IMPORT; RUN;

DATA WORK.IMPORT;
INFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';
observations = input(FRED_Graph_Observations, 10.); RUN;
b_int = input(B, 10.); RUN;


%web_open_table(WORK.IMPORT);
 
This returns
ERROR 180-322: Statement is not valid or it is used out of proper order.

Thanks

 


 

View solution in original post

5 REPLIES 5
Astounding
PROC Star

You will need to learn what goes into a DATA step.  For now, there are two points to consider:

 

  • You have an extra RUN statement.  You need one at the end of the DATA step, but you have an extra one in the middle.
  • Importing the data creates a SAS data set named IMPORT.  If you want to use it, you don't need an INFILE statement.  Instead, use:

data import2;

set import;

observations = input(FRED_Graph_Observations, 10.);
b_int = input(B, 10.);

RUN;

 

Once you have a SAS data set, you don't need to refer to the spreadsheet that was used to create it.

profjustin
Calcite | Level 5

Thank you!

Reeza
Super User

You should comment your steps, it helps to find logical issues in your process:

 

Your issue is with the data step. Since you've already read in the file you don't need to read it in again and you can't read Excel files with INFILE.I would really recommend using more descriptive data set names as well. You also have a RUN statement too early, it ends the data step when you still want to do calculations. 

 

DATA Import2;

set Import;

observations = input(FRED_Graph_Observations, 10.); 

b_int = input(B, 10.);

 RUN;

Ideally your program would look like the following, note the comments and I changed the items in red. Hopefully this works for you 🙂

*path to file to import into SAS;
FILENAME REFFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';

*Import Excel File;
PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=Fred_GDP;
    GETNAMES=YES;
RUN;

PROC CONTENTS DATA=FRED_GDP; RUN;

*convert variables to numbers;
data fred2;
set fred_gdp;

observations = input(FRED_Graph_Observations, 10.); *remove early RUN;
b_int = input(B, 10.); 

 RUN;


@profjustin wrote:

Hello,

Would someone be able to help me fix this error code?

FILENAME REFFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';

PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=WORK.IMPORT;
    GETNAMES=YES;
RUN;

PROC CONTENTS DATA=WORK.IMPORT; RUN;

DATA WORK.IMPORT;
INFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';
observations = input(FRED_Graph_Observations, 10.); RUN;
b_int = input(B, 10.); RUN;


%web_open_table(WORK.IMPORT);
 
This returns
ERROR 180-322: Statement is not valid or it is used out of proper order.

Thanks

 


 

Kurt_Bremser
Super User
DATA WORK.IMPORT;
INFILE '/folders/myfolders/MIS445/MIS445_FRED-real_GDP.xlsx';
/* you cannot read an Excel file with a data step. Data steps can read text files */
observations = input(FRED_Graph_Observations, 10.); RUN;
/* the previous RUN ends the data step, causing the next statement to be in "open code", where it is not valid */
b_int = input(B, 10.); RUN;

As you already have created WORK.IMPORT with the previous proc import (if that worked), but need to convert variables of type character into new ones of type numeric, you can change your data step to this:

data work.import;
set work.import;
observations = input(FRED_Graph_Observations, 10.);
b_int = input(B, 10.);
run;
ballardw
Super User

INFILE tells SAS that you are going to write input specifications to read a text file. XLSX are not text files. A single RUN statement will end a data step.

You should show the entire log of the code submitted plus the error message. Copy from the log and paste into a code box opened with the forum's {I} or "running man" icon. The particular error you show should have at least one line of code with underscores indicating the invalid syntax. If you paste the entire code step with the error in a code box the format of the message will be maintained and we can provide more help.

 

Likely you wanted to manipulate something in the WORK.IMPORT data set. You reference that in a SET statement. Do not go back and attempt to reread the xlsx.

 

Something like this maybe. Note that while the syntax allows the same input and output set names doing so often leads to hard to diagnose data issues as the code would completely replace the original data set. If the logic is incorrect then you need to go back to get the original input set.

data work.import2;
   set work.import;
   observations = input(FRED_Graph_Observations, 10.);
   b_int = input(B, 10.); 
RUN;

RUN will end a data step block of code. So everything after your first RUN; was syntactically wrong as well. The input calls are only needed if the variable is character.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1166 views
  • 2 likes
  • 5 in conversation