There is no easy way to convert a SAS file to a STATA file to input very large NHANES data files. This program can do that.
This program has been validated with public use adult.sas (save as adult.txt by a free SAS viewer) and
adult.dat files. These files could be downloaded from NHANES III website by the public.
This program expects 1. the filename of a SAS file provided by NCHS NHANES, 2. the filenanme of a STATA 12 do-file, 3. the filename of a STATA do-file to store the formats and 4. the NHANES data file
Commands to run the script:
SASCodeFileName='adult.txt' STATADoFileName = 'stataadult1.txt'
STATADoFileName = 'stataadult1.txt' NHANESDataFileName = 'adult.dat'
NHANESCOPEConvertSASCodeToSTATACodeToReadNHANESDataFileSuccess = NHANESCOPEConvertSASCodeToSTATACodeToReadNHANESDataFile(SASCodeFileName,STATADoFileName, STATAFormatDOFileName, NHANESDataFileName)
This program has been tested without problems in STATA 12:
1. Make sure adult.dat is in the STATA working directory.
2. Load the stataadult1.txt, save as a do-file, run it, you will get 1238
%variables and 20050 records (rows)
3. Load the stataadultformat1.txt, save as a do-file, run it, you will
have all the variables formatted according to the formatting information
in the SAS file.
NOTE the STATA needs to load the data before it can format them
Rex Cheung (2019). NHANESCOPEConvertSASCodeToSTATACodeToReadNHANESDataFile (https://www.mathworks.com/matlabcentral/fileexchange/40033-nhanescopeconvertsascodetostatacodetoreadnhanesdatafile), MATLAB Central File Exchange. Retrieved .