Sas To Stata
In SAS, PROC FORMAT is a convenient way to apply value labels to categorical variables. Unfortunately, SAS does not automatically save custom formats when a data set is saved. This makes it inconvenient to STAT/TRANSFER to convert to Stata.
Here's a solution:
LIBNAME hdformat 'D:\public\hd\formats';
PROC FORMAT library=hdformat;
VALUE MARCOHAB
1 ="Married, living with spouse"
2 ="Married, spouse absent"
3 ="Separated--Cohabiting"
4 ="Divorced--Cohabiting"
5 ="Widowed--Cohabiting"
6 ="Never married--Cohabiting"
7 ="Separate--Not cohabiting"
8 ="Divorced--Not cohabiting"
9 ="Widowed--Not cohabiting"
10 ="Never married--Not cohabiting"
;
VALUE MB2F
1 ="Married"
2 ="Separated, because of marital problems"
3 ="Divorced"
4 ="Widowed"
5 ="Never married"
7 ="Refused"
9 ="Inap/no answer"
99 ="Unknown"
;
To use these formats, just include the following before your DATA step:
LIBNAME hd 'd:\public\HD'; options fmtsearch=(hd);
If saved, STAT/TRANSFER can then use these formats when it does a conversion to another format, like Stata. My version of Stat/Transfer, automatically looks for the format file using a particular name and directory which can be set under Options. Not the most intuitive interface, but with trial and error it not too hard to figure out.

Categories: SAS, Stata, StatTransfer, Hacks