Skip to content

Instantly share code, notes, and snippets.

@joosti
Last active August 29, 2015 14:16
Show Gist options
  • Save joosti/2cd561d5f44d7f223bbf to your computer and use it in GitHub Desktop.
Save joosti/2cd561d5f44d7f223bbf to your computer and use it in GitHub Desktop.
SAS export to Mongodb
/*
Export of SAS dataset to Mongodb
*/
/* References to project folders */
%let projectDir = E:\research\projects\myProject\;
%let mongoExportDir = &projectDir.sas\export to mongo\;
/* Path to Mongoimport executable */
%let mongoimportPath = 'C:\Program Files\MongoDB\Server\3.0\bin\mongoimport.exe';
/* helper macro */
%macro myExport(dset=, file=);
%let filename = "&file"; proc export data= &dset outfile=&filename dbms=csv replace;run;
%mend;
/* Export to csv */
%myExport(dset=a.e_exportMongo, file=&mongoExportDir.myExportFile.csv);
/* Change current directory to directory with csv (for convenience)*/
X CD &mongoExportDir;
/* Run mongoimport (note: records are appended) */
systask command "&mongoimportPath -d dbname -c collectionname --type csv --file myExportFile.csv --headerline" ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment