SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

exporting text formatted values to STATA

Reply
Occasional Contributor
Posts: 13

exporting text formatted values to STATA

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?

 

Super User
Posts: 13,950

Re: exporting text 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.

Ask a Question
Discussion stats
  • 1 reply
  • 89 views
  • 0 likes
  • 2 in conversation