Import XLSX file in SAS starting from the third row, using other option than RANGE - sas

We can import an XLS file using namerow and startrow, like in this example :
%let dir_n=TheDir_name;
%let fichimp=file_name.xls;
PROC IMPORT DATAFILE= "&dir_n.\&file_name."
out=want
dbms=xls replace;
sheet=theSheet_name;
getnames=no;
namerow=2;
startrow=3;
run;
I have read : To import XLSX file, use RANGE if the data is not starting on the first line.
Is there similar option to STARTROW to import XLSX file starting from a specific row?

No, there is not. dbms=XLSX only has a limited set of options, listed in the documentation: GETNAMES, SHEET, and RANGE.
EXCEL has a few more options (including DBDSOPTS which opens up several database-type options), but still uses range to control what is read in.

Related

Effectively read multiple excel sheets from an xlsx excel workbook in SAS 9.4M7

I am trying to read multiple sheets from an excel workbook (xlsx format) in SAS. Instead of using two separate proc imports, is there a way to simultaneously read multiple excel sheets from an excel workbook? My code thus far is as follows:
proc import datafile= "&loc.\&exid..xlsx"
out=exp
dbms=xlsx replace;
sheet="Sheet1";
run;
proc import datafile= "&loc.\&exid..xlsx"
out=dt
dbms=xlsx replace;
range="'Sheet5'$A2:AB10000";
getnames=yes;
run;
It is taking ~1.40 secs to read both of these excel sheets from one excel workbook, how do I reduce the time it takes to read xlsx workbook in SAS.
If you have SAS/CONNECT, you can run the two imports in parallel with rsubmit. I tested this out on an Excel file and it did not give any simultaneous access errors. Since each import is only about 1.4 seconds, this might take longer in aggregate since it needs to spin up two new SAS sessions to run each import.
options autosignon = yes
connectwait = no
sascmd = '!sascmd'
;
libname worklib "%sysfunc(getoption(work))";
/* Send over macro variables to rsubmit sessions */
%syslput _USER_ / remote=session1;
%syslput _USER_ / remote=session2;
rsubmit remote=session1 inheritlib=(worklib);
proc import datafile= "&loc.\&exid..xlsx"
out=worklib.exp
dbms=xlsx replace;
sheet="Sheet1";
run;
endrsubmit;
rsubmit remote=session2 inheritlib=(worklib);
proc import datafile= "&loc.\&exid..xlsx"
out=worklib.dt
dbms=xlsx replace;
range="'Sheet5'$A2:AB10000";
getnames=yes;
run;
endrsubmit;

After using proc import on an excel file, how am i able to use that data?

I've imported the excel file and it says the data file work.one has been created, but how am i able to manipulate this file?
What im trying to do is transform PSA to ln(PSA+1) in most analyses using PSA, where PSA is the excel file I imported. I am using base SAS.
This is my code so far
data excl;
proc import out = psa
datafile= "H:\MinitabFiles\Morrell\SAS-Data\psa.xls"
dbms = xls replace;
sheet = "psa";
getnames = yes;
run;
data logs;
set excl;
sheet = log(sheet+1);
run;'
What do you want to do with it?
You'll find it in the work library under the explorer tree assuming you are using Enterprise Guide. To 'manipulate' it, many of your most obvious options will be covered by proc sql; or a datastep.
Please elaborate on the question if you want a more useful answer:-
1 which sas product are you using? EG, Base, etc?
2 have you located the file and established it has been imported correctly?
3 `manipulate'? What does this mean? Filter, perform calculations, functions, conversions or one of many other things.
Welcome btw, but please provide plenty more detail.
You have issues with your current code. For example the data excl doesn't do anything. PROC IMPORT creates the data, the data step around the PROC IMPORT is useless.
data excl; *REMOVE THIS, DOES NOT DO ANYTHING;
proc import out = psa /*PSA is the name of the output data set*/
datafile= "H:\MinitabFiles\Morrell\SAS-Data\psa.xls"
dbms = xls replace;
sheet = "psa";
getnames = yes;
run; *THIS GOES WITH THE PROC IMPORT;
data logs;
set excl; *YOUR DATASET IS CALLED PSA, replace EXCL with PSA;
sheet = log(sheet+1); *This assumes your PSA data set has a variable with sheet;
run;'

SAS import single cell value from Excel spreadsheet

I am using sas 9.2 and i want top import a cell value from a spreadsheet
the value i want are F4 located in the sheet "data beskrivelse"
This i what i do:
proc import out=TESTER
datafile="&request_in"
dbms=XLS replace;
RANGE="data beskrivelse$F4:F5";
run;
And it works ok, but the result is that the column name gets the value in F4 and
the data from F5 is imported.
So my sas dataset has ha column where the header name are the value of F4.
if i change the range in proc import to
proc import out=TESTER
datafile="&request_in"
dbms=XLS replace;
RANGE="data beskrivelse$F4:F4";
run;
I'll get the whole column imported from the spreadsheet.
So basically i want the value from F4 to be imported into my sas dataset in variable A
Oh i managed to figure it out,
the solution is to use the getnames option in proc imort
it says wether to import as names or not.
so i changed to this
proc import out=TESTER
datafile="&request_in"
dbms=XLS replace;
getnames=NO;
RANGE="data beskrivelse$F4:F4";
run;
and i get the value in as data in my dataset.

SAS Import XLS file without headings

I am importing an XLS file with dataset looking like this:
And my code was as below:
%let dirLSB=/folders/myfolders/sasuser.v94/;
proc import datafile="&dirLSB.OnionRing.xls" out=sales replace;
run;
proc print data=sales label;
run;
But the result showed the first row had been treated as headings and the
row data for the first row "Columbia Peaches" was missing.
It should have been four rows but in the end, only three rows were present.
Are there any suggestions?
Thanks a lot!!!
Just add the getnames=no; statement to your proc import step.
proc import datafile="&dirLSB.OnionRing.xls" out=sales replace;
getnames=no;
run;

SAS says data contains no columns when using linear regression

I'm new to SAS and am having issues with using Linear Regression.
I loaded a CSV file and then in Tasks and Utilities > Tasks > Statistics > Linear Regression I selected WORK.BP (BP = filename) for my data. When I try to select my dependent variable SAS says "No columns are available."
The CVS file appears to have loaded correctly and has 2 columns so I can't figure out what the issue is.
Thanks for the help.
This is the code I used for loading the file:
data BP;
infile '/folders/myfolders/BP.csv' dlm =',' firstobs=2;
input BP $Pressure$;
run;
And this is what the output looks like
By running your code. you import the .csv file with the 'PRESSURE' variable as character variable; in a linear regression model, you need to have all varaible as _numeric_.
In order to do this, I suggest to use the PROC IMPORT to import a .csf format file, instead of a DATA step with an INPUT statement.
In your case, you shold follows those steps:
Define the path where the .csv file is located:
%let path = the_folder_path_where_the_csv_file_is_located ;
Define the number of rows from which start your data (by including the labels/variables names in the count):
%let datarow = 2;
Import the .csv file, here named 'BP', as follows:
proc import datafile="&path.\BP.csv"
out=BP
dbms=csv
replace;
delimiter=",";
datarow=&datarow.;
getnames=YES;
run;
I assumed that the file you want as output has to be called BP too (you'll find it in the work library!) and that the delimiter is the colon.
Hope this helps!