proc format;
value $sex
1="Female"
2="Male"
;
value $ethnic
1="Chinese"
2="Malay"
3-"Indian"
4="Others"
other="Unknown"
;
run;
data dm;
infile datalines ;
input pat $ sex $ ethnic $ brthdat : date9.;
format sex $sex. ethnic $ethnic.;
datalines;
001 1 1 23Jan1970
002 1 2 28Mar1977
003 1 3 31Aug1964
004 1 4 14Feb1967
005 2 1 09Apr1987
006 2 2 12Apr1956
007 2 3 05Dec1990
008 2 4 09Sep1983
009 1 . .
010 2 . .
;
run;
proc print;
format brthdat date9.;
run;
proc export data=work.dm file="c:\dm.dta" dbms=stata replace;
run;The DTA file is only showing the data values for SEX and ETHNIC variables. How do i export the formatted values to STATA?
Easiest would likely be to add variables with the applied format such as:
data dm; infile datalines ; input pat $ sex $ ethnic $ brthdat : date9.; format sex $sex. ethnic $ethnic.; sexf= put(sex,$sex.); ethnicf=put(ethnic,$ethnic.); drop sex ethnic; datalines; 001 1 1 23Jan1970 002 1 2 28Mar1977 003 1 3 31Aug1964 004 1 4 14Feb1967 005 2 1 09Apr1987 006 2 2 12Apr1956 007 2 3 05Dec1990 008 2 4 09Sep1983 009 1 . . 010 2 . . ; run;
Another might be to Proc Print the data with the formats applied to a text file (ods listing) and use STATA import tools. I am not familiar with STATA to know if that may be easy or not.
Proc Export doesn't use formats for any of the output destinations that I've ever used.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.