SASWRITE
Write numeric data to a SAS dataset
Contents
Syntax
saswrite(array,sasfile,xlsfile)
saswrite(array,sasfile,xlsfile,names)
Inputs
array - numeric array
sasfile - full path to input SAS dataset
xlsfile - full path to Excel workbook containing SAS2Excel macro
names - SAS column names, cell array of strings (optional)
Outputs
(none)
Description
saswrite invokes xlswrite to write array to a temporary Excel workbook, then uses Microsoft Excel, manipulated via ActiveX automation server, to open an instance of SAS and execute IMPORT procedure, transferring data to a SAS dataset.
Both SAS (including SAS/ACCESS Interface to PC Files) and Excel are needed to run saswrite. Excel workbook containing SAS2Excel macro must be retained, its path provided in xlsfile.
C:\sas.xls is used for temporary data storage; if you do not have write access to C:, edit all references to C:\sas.xls in sasread and SAS2Excel macro.
saswrite will ask you to close any open SAS sessions.
During transfer, you will be presented with a 'Save changes?' dialog by Excel; select 'Do not save changes'. (Suggestions on how to suppress this behavior are welcome).
sasfile and xlsfile must provide absolute file paths; file extensions may be omitted.
Example
array = rand(2) %#ok
array =
0.4154 0.8744
0.3050 0.0150
dir('C:\*.sas7bdat')
sasreaddemo.sas7bdat
sasfile = 'C:\saswritedemo.sas7bdat'; xlsfile = 'C:\SAS-Matlab Converter.xls'; saswrite(array,sasfile,xlsfile) dir('C:\*.sas7bdat')
sasreaddemo.sas7bdat saswritedemo.sas7bdat
[numeric,text,raw] = sasread(sasfile,xlsfile) %#ok
numeric =
0.4154 0.8744
0.3050 0.0150
text =
'F1' 'F2'
raw =
'F1' 'F2'
[0.4154] [0.8744]
[0.3050] [0.0150]
See also
sasread (companion File Exchange submission)
xlsread
actxserver
Author
Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 11/1/05
