<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Export SAS dataset to STATA keeping the formats in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629219#M77623</link>
    <description>&lt;P&gt;What does your SAS log show?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like told PROC FORMAT to store the formats in a catalog named FORMATS.FORMATS and you told PROC EXPORT to use the formats in a catalog named WORK.FORMATS.&amp;nbsp; Make sure that you tell PROC EXPORT to use the catalog that actually has the format definitions.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Mar 2020 19:22:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-03-03T19:22:05Z</dc:date>
    <item>
      <title>Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629116#M77615</link>
      <description>&lt;P&gt;Hi, i have to convert my sas dataset into stata keeping the formats i created but i can't do it.&lt;/P&gt;&lt;P&gt;I've even tried to make it on an easy example but still don't work.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname formats "...\Formats";
option fmtsearch=(formats);

Proc format lib=formats;
value $nationalite
"1" = "Française"
"2" = "CEE"
"3" = "Hors CEE";
quit;

data test;
input a$;
cards;
1
1
2
2
3
;
run;

data test2;
set test;
format a $nationalite.;
run;

PROC EXPORT DATA=test2
OUTFILE="...\base.dta"			
DBMS=dta REPLACE;
fmtlib=formats;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The formats are attached to my sas dataset, but when i export this to stata with fmtlib option, stata ignores my formats, do you know why? Something is missing?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 13:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629116#M77615</guid>
      <dc:creator>Vincent5</dc:creator>
      <dc:date>2020-03-03T13:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629158#M77619</link>
      <description>&lt;P&gt;The note under exporting SAS to stat has this note related to value labels:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;When writing SAS data to a Stata file, the EXPORT procedure saves the value labels that are associated with the variables. The procedure uses the formats that are associated with the variables to retrieve the value entries. You can use the FMTLIB=&lt;SPAN class="xis-userSuppliedValue"&gt;libref.format-catalog&lt;/SPAN&gt; statement to tell SAS where to locate the formats catalog.&lt;/P&gt;
&lt;DIV class="xis-note" id="p14z9i30li6pwqn1b5yr2zd4npoz"&gt;&lt;STRONG&gt;&lt;SPAN class="xis-noteGenText"&gt;Note: &lt;/SPAN&gt;Numeric formats only&lt;/STRONG&gt;.&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For character values you may need to go through a data step to create a new data set and create the formatted value(s) of character variables by using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = put(variablename, characterformat.);&lt;/P&gt;
&lt;P&gt;and then exporting that data set instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 16:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629158#M77619</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-03T16:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629165#M77620</link>
      <description>&lt;P&gt;Thank you for your answer, i didn't know that.&lt;/P&gt;&lt;P&gt;But i also tried converting character to numeric value before posting and that still don't apply format in STATA:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname formats "C:\Users\vincent.dibeo\Documents\ANPAA - CSAPA\CSAPA sentinelle\Données\Formats\test";
option fmtsearch=(formats);

Proc format lib=formats;
value nationalite
1 = "Française"
2 = "CEE"
3 = "Hors CEE";
quit;

data test;
input a;
cards;
1
1
2
2
3
;
run;

data test2;
set test;
format a nationalite.;
run;


PROC EXPORT DATA=test2
OUTFILE="C:\Users\vincent.dibeo\Documents\ANPAA - CSAPA\CSAPA sentinelle\Données\Formats\test\base.dta"			
DBMS=dta REPLACE;
fmtlib=formats;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your suggestions is not convenient because i don't want to overwrite initial values by characters formats (i want to keep values and associated formats like i have in sas), it is impossible? &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 16:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629165#M77620</guid>
      <dc:creator>Vincent5</dc:creator>
      <dc:date>2020-03-03T16:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629200#M77622</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314830"&gt;@Vincent5&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your answer, i didn't know that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your suggestions is not convenient because i don't want to overwrite initial values by characters formats (i want to keep values and associated formats like i have in sas), it is impossible? &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I really did not suggest "overwrite initial values". I suggested creating additional new variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't use STATA, don't have access to STATA and can't really say what may be going on. I know that for some file formats the version SAS exports may not be native to the very latest release and so you may be able to tell the other program to treat the file as the version SAS exports. But I don't know if that is possible or how to do it. The documentation I looked at in SAS says that SAS supports STATA 12 and earlier versions.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 17:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629200#M77622</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-03T17:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629219#M77623</link>
      <description>&lt;P&gt;What does your SAS log show?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like told PROC FORMAT to store the formats in a catalog named FORMATS.FORMATS and you told PROC EXPORT to use the formats in a catalog named WORK.FORMATS.&amp;nbsp; Make sure that you tell PROC EXPORT to use the catalog that actually has the format definitions.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 19:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629219#M77623</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-03T19:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629387#M77624</link>
      <description>&lt;P&gt;Thank you for your messages, i made the correction: "fmtlib = formats.formats" in the proc export but that didn't resolve the problem.&lt;/P&gt;&lt;P&gt;I noticed that even if i write anything like "fmtlib=aaaaa.bbbb" (doesn't exist), sas log show:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;The export data set has 5 observations and 1 variables.
NOTE: "...\base.dta" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It seems that sas (or just sas log..) ignores fmtlib option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 09:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629387#M77624</guid>
      <dc:creator>Vincent5</dc:creator>
      <dc:date>2020-03-04T09:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629609#M77632</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Use the exact same two level name in the PROC FORMAT statement and the FMTLIB statement.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure the catalog has the formats.&amp;nbsp; Make sure the variables are numeric. Make sure the formats are simple 1-1 mappings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this test and open the two files in STATA and see if it works.&amp;nbsp; It looks to me like SAS has include value labels in the formats.dta file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=%sysfunc(pathname(work));

proc format lib=&lt;FONT color="#FF0000"&gt;work.formats&lt;/FONT&gt; ;
 value sexf 0='MALE' 1='FEMALE' ;
run;
data test;
  set sashelp.class ;
  keep sexf;
  sexf=sex='F';
  format sexf sexf. ;
run;

proc export data=test
  outfile="&amp;amp;path/formats.dta" replace
;
  fmtlib=&lt;FONT color="#FF0000"&gt;work.formats&lt;/FONT&gt;;
run;
proc export data=test
  outfile="&amp;amp;path/noformats.dta" replace
;
  fmtlib=zzzwork.formats;
run;
data _null_;
  infile "&amp;amp;path/formats.dta" lrecl=100 recfm=f obs=20;
  input;
  list;
run;

data _null_;
  infile "&amp;amp;path/noformats.dta" lrecl=100 recfm=f obs=20;
  input;
  list;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I dump the file as binary the end of the file looks like this:&lt;/P&gt;
&lt;PRE&gt;5   CHAR  ..............................$...sexf........................................................&lt;FONT color="#FF0000"&gt;MALE.F&lt;/FONT&gt;
    ZONE  0000000000000000000000000000002000767600000000000000000000000000000000000000000000000000000000444404
    NUMR  00000000000000000000000000000040003586000000000000000000000000000000002000C0000000500000001000D1C506

6   CHAR  &lt;FONT color="#FF0000"&gt;EMALE&lt;/FONT&gt;. 6
    ZONE  444440
    NUMR  5D1C50&lt;/PRE&gt;
&lt;P&gt;And the onw where I pointed it at a non-existent catalog the MALE FEMALE text is not in the file.&lt;/P&gt;
&lt;PRE&gt;4   CHAR  ð?......ð?......................ð?......ð?......................ð?......ð?......ð?......ð?..........
    ZONE  F3000000F30000000000000000000000F3000000F30000000000000000000000F3000000F3000000F3000000F30000000000
    NUMR  0F0000000F00000000000000000000000F0000000F00000000000000000000000F0000000F0000000F0000000F0000000000

5   CHAR  .............................. 30
    ZONE  000000000000000000000000000000
    NUMR  000000000000000000000000000000&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 21:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629609#M77632</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-04T21:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629768#M77635</link>
      <description>&lt;P&gt;Thank you, i've finally found the problem thanks for your help.&lt;/P&gt;&lt;P&gt;It's just that length of formats names should not exceed 8 characters (i imagine it's the maximum format name size in stata), and in my example, my format name is "nationalite" which has 11 characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i just have to convert my characters variables into numerics for which i want to apply a format, and then reduce size (bellow 8 characters) of my formats names and it should work ! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 10:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/629768#M77635</guid>
      <dc:creator>Vincent5</dc:creator>
      <dc:date>2020-03-05T10:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/762101#M80914</link>
      <description>&lt;P&gt;Has the issue been solved?&lt;/P&gt;&lt;P&gt;I have the same issue, and the lengths for my variable format names are not longer than 8.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 15:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/762101#M80914</guid>
      <dc:creator>KJL</dc:creator>
      <dc:date>2021-08-17T15:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS dataset to STATA keeping the formats</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/844690#M82291</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;The fact that the exported datasets does not have any formats attached to a variable where format name is &amp;gt;8 Character long is not a problem of Stata. Because, I have checked that Stata 17 can create formats with name longer than 8 character and attach them to variables without any problems. I also replicated the SAS code to create a SPSS datafile which also has the same problem. Thus, it looks to me an issue with the FMTLIM statement in PROC EXPORT.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 19:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Export-SAS-dataset-to-STATA-keeping-the-formats/m-p/844690#M82291</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2022-11-16T19:17:32Z</dc:date>
    </item>
  </channel>
</rss>

