SAS import single cell value from Excel spreadsheet - sas

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.

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 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;

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

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.

How to import an excel to sas with getnames = no?

I want to specify new names so I use getnames=no property:
data mylib.test;
infile "C:\Users\test.xlsx" ;
input var1 $ Opened_Date mmddyy8. salary dollar9.2;
DBMS=EXCEL ;
range="Sheet5$";
getnames=no;
mixed=no;
scantext=yes;
usedate=yes;
scantime=yes;
datarow=3;
run;
But this does not import anything
PS the following code with getnames=yes works fine . This means that there is no problems with excel file . But i don't want to use yes I need getnames=no
PROC IMPORT OUT= WORK.TEST
DATAFILE= "C:\Userstest.xlsx"
DBMS=EXCEL REPLACE;
RANGE="Sheet5$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
PROC IMPORT OUT= WORK.TEST
DATAFILE= "C:\Userstest.xlsx"
DBMS=EXCEL REPLACE;
RANGE="Sheet5$";
GETNAMES=NO;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
The data step is not helpful in this case. You can't import an excel file that way (practically speaking).
After this, you then create a data step and can rename things however you want from the generic names initially assigned by the PROC IMPORT.
An alternative that looks like the data step method is libname access.
libname myexcel excel "c:\Usertest.xlsx" getnames=no scantext=yes mixed=no usedate=yes scantime=yes;
Then you can access the file like
data test;
set myexcel,'Sheet5$'n;
rename f1=var1 f2=opened_date (...more...);
run;
I tend to use PROC IMPORT as it's a bit easier to understand for others, but both are equivalent in how they work (PROC IMPORT creates this libname for you, basically).