BookmarkSubscribeRSS Feed
Dennis_K
Obsidian | Level 7
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?

 

1 REPLY 1
ballardw
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 1 reply
  • 799 views
  • 0 likes
  • 2 in conversation