Hello,
Would someone be able to help me fix this error code?
ERROR 180-322: Statement is not valid or it is used out of proper order.
Thanks
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 returnsERROR 180-322: Statement is not valid or it is used out of proper order.Thanks
You will need to learn what goes into a DATA step. For now, there are two points to consider:
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.
Thank you!
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 returnsERROR 180-322: Statement is not valid or it is used out of proper order.Thanks
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;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.