Dear experts,
I received this error 180-322 message while I was trying to run below:
PROC IMPORT OUT= WORK.FISCAL
DATAFILE= "D:\Summer 2019 Work\Summer19\Ke Summer Data"
DBMS= XLS;
RANGE="Sheet1$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
And this is the detailed error message:
1 PROC IMPORT OUT= WORK.FISCAL
2 DATAFILE= "D:\Summer 2019 Work\Summer19\Ke Summer Data"
3 DBMS= XLS;
NOTE: The previous statement has been deleted.
NOTE: The previous statement has been deleted.
4 RANGE="Sheet1$";
NOTE: The previous statement has been deleted.
5 GETNAMES=YES;
6 MIXED=NO;
7 SCANTEXT=YES;
--------
180
8 USEDATE=YES;
-------
180
9 SCANTIME=YES;
--------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
I'm not sure what happened. Could someone please help me out? Thanks very much!
Maybe try DBMS=EXCEL instead? I couldn't find any documentation on DBMS=XLS that had all of the options you listed. See https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=acpcref&docsetTarget=n... for more documentation.
How about showing the actual entire name of the data file???
DATAFILE= "D:\Summer 2019 Work\Summer19\Ke Summer Data" is sort of incomplete from many purposes.
You may also have to check to see if someone "lied" to Excel. You will find people that create files as HTML, XML or even CSV but name the file with XLS or extension so Excel will be the default program to open the file. Any of those will likely fail to import.
Or try doing a FILE SAVE AS from Excel to a CSV format and import that.
@ballardw Thank you very much but my problem remains... I double checked the file, the data file property shows that it's an xls file. I even tried convert it into a csv and an xml file. Neither one works when I tried to import them into SAS...
Why don't you specify the proper file name?
DATAFILE= "D:\Summer 2019 Work\Summer19\Ke Summer Data.xls"
@ChrisNZ Thanks a lot for your help. I added xls to the file name but the problem remains. But it worked when I saved the xls file as a csv file and deleted below rows:
RANGE="Sheet1$";
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
So now I'm using this and it works out well:
PROC IMPORT OUT= WORK.FISCAL
DATAFILE= "D:\OD - Copy\Research Projects\Dr. Johnson\CEO effect\Summer 2019 Work\Summer19\Ke_Summer_Data.csv"
DBMS=CSV REPLACE; GETNAMES=YES;
RUN;
But I'm not sure whether deleting the setting of date format etc damaged the dataset...
Can't comment further without seeing more code, but the messages you were seeing relate to invalid/incompatible values for the different options chosen (DBMS= SCANTEXT= USEDATE= SCANTIME= etc). Not all engines use all options.
@ChrisNZ Thanks again for clarifying. I think the data imported to SAS is good. So I'll go with the reduced code. Have a nice weekend!
@kegong wrote:
@ChrisNZ Thanks a lot for your help. I added xls to the file name but the problem remains. But it worked when I saved the xls file as a csv file and deleted below rows:
RANGE="Sheet1$";
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
So now I'm using this and it works out well:
PROC IMPORT OUT= WORK.FISCAL
DATAFILE= "D:\OD - Copy\Research Projects\Dr. Johnson\CEO effect\Summer 2019 Work\Summer19\Ke_Summer_Data.csv"
DBMS=CSV REPLACE; GETNAMES=YES;
RUN;
But I'm not sure whether deleting the setting of date format etc damaged the dataset...
I suggest also using GUESSINGROWS=MAX; This option, not available for XLS, XLSX and many database formats, works with delimited text such as CSV to examine the entire dataset before guessing as the variable type and length. SCANTEXT is somewhat similar in purpose.
But do look at the data step code generated to ensure the variables are read as needed.
@ballardw Thank you so much. It works pretty well.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.