/* This program converts a SAS data file (.sas7bdat) to Stata (.dta) in the input_data folder. NB: All variables in the new Stata file are in " double" format, instead of int or byte since SAS is not able to compress this when exporting, which results in .dta files that take up ~3x as much space. It is currently -Mar 2020- in the list of feature requests so this may get fixed in the future. For now, in the Stata program that uses the newly generated Stata file, be sure to use 'compress' to save space. Since 'compress' in Stata iterates over all variables, it can take a while especially with a wide file, so it is faster to compress in Stata when there are fewer variables (e.g. at the end, after reshaping) */ /* retrieve the file path from the Makefile for the containing folder and filename from the input SAS file */ %let filepath=%sysget(FILEPATH); /* extract the SAS filename (last word of file path (/) before the sas7bdat suffix (.) ) */ %let filename=%scan(%quote(%scan(%quote(&filepath.),-1,%str(/))),1,%str(.)); /* extract the directory that holds the SAS file (strip .sas7bdat extension and the filename from the filepath) */ %let datadir= %sysfunc(tranwrd(%sysfunc(tranwrd(&filepath.,.sas7bdat,%str())),&filename.,%str())); libname datadir "&datadir."; /* convert the file to dta and save in the same data directory*/ proc export data=datadir.&filename. file="&datadir.&filename..dta" DBMS=stata replace; run;