<?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: How to get value labels from SAS to Stata in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571927#M12249</link>
    <description>&lt;P&gt;Proc Export sends the data to the file, not the labels. So, if you want to send the formatted values, you will have to create a new variable with a put statement. Then you can export that file.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	length year_in_college_t $ 32; 
		*Make sure that the length of the string variable is long enough for the longest label in the format.;
	year_in_college_t=put(year_in_college,MyCollFormat.); *Use your format here.;
	*Add other variables and formats here.;
	drop year_in_college;
run;

*Alternatively if you need to keep the variable names ;
data want;
	set have (rename=year_in_college=year_in_college_old;
	length year_in_college $ 32; 
		*Make sure that the length of the string variable is long enough for the longest label in the format.;
	year_in_college=put(year_in_college_old,MyCollFormat.); *Use your format here.;
	*Add other variables and formats here.;
	drop year_in_college_old;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 Jul 2019 00:21:56 GMT</pubDate>
    <dc:creator>heffo</dc:creator>
    <dc:date>2019-07-09T00:21:56Z</dc:date>
    <item>
      <title>How to get value labels from SAS to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571926#M12248</link>
      <description>&lt;P&gt;I have been struggling to get data transferred from SAS to Stata for the past few days. My trouble is that while I can get the variable labels transferred between them, I cannot get the value labels transferred.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if a variable is year_in_college, the variable label is `Year in College', and the value labels are `Freshman' for the value 1, `Sophomore' for the value 2, etc., then I can get the variable label into Stata, but the value labels of `Freshman' etc, do not appear in Stata.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to find a solution without success. The relevant SAS code that I have been trying without success is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC EXPORT DATA= OUT.data_to_export&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; OUTFILE = `C:\Users\NAME\Desktop\Data\stata_dataset.dta''&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; DBMS= STATA LABEL REPLACE;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; FMTLIB= LIB.FORMATS;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 00:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571926#M12248</guid>
      <dc:creator>bourne3rd</dc:creator>
      <dc:date>2019-07-09T00:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to get value labels from SAS to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571927#M12249</link>
      <description>&lt;P&gt;Proc Export sends the data to the file, not the labels. So, if you want to send the formatted values, you will have to create a new variable with a put statement. Then you can export that file.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	length year_in_college_t $ 32; 
		*Make sure that the length of the string variable is long enough for the longest label in the format.;
	year_in_college_t=put(year_in_college,MyCollFormat.); *Use your format here.;
	*Add other variables and formats here.;
	drop year_in_college;
run;

*Alternatively if you need to keep the variable names ;
data want;
	set have (rename=year_in_college=year_in_college_old;
	length year_in_college $ 32; 
		*Make sure that the length of the string variable is long enough for the longest label in the format.;
	year_in_college=put(year_in_college_old,MyCollFormat.); *Use your format here.;
	*Add other variables and formats here.;
	drop year_in_college_old;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jul 2019 00:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571927#M12249</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-09T00:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get value labels from SAS to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571928#M12250</link>
      <description>Thanks for the quick reply! Does there happen to be a faster way? Unfortunately, I am dealing with hundreds of variables so this would be quite tedious to do for all of them.</description>
      <pubDate>Tue, 09 Jul 2019 00:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571928#M12250</guid>
      <dc:creator>bourne3rd</dc:creator>
      <dc:date>2019-07-09T00:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get value labels from SAS to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571934#M12251</link>
      <description>&lt;P&gt;I'm not sure it will work fully and it does change the order of the table. But here it is.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Create a custom format;
proc format;
	value $sex 	"F" = "Female"
				"M" = "Male";
	value age 	1-10 = "Youngling"
				11-18 = "Master";
run;
*use the custom format;
data class;
	set sashelp.class;
	format sex $sex. age age. Weight 4.;
run;

*Actual macro to be used;
%macro reformat(ds_in, ds_out);
	*Get the variables with formats in them;
	proc contents data=&amp;amp;ds_in out=variables (keep=Name format where=(format is not missing)) noprint ;
	run;
	*Fix that the formats migth not have a . in them.;
	data variables;
		set variables;
		*Do not touch numeric formats that is on the form w.d or w.;
		if lengthn(compress(format,"1234567890.,"))&amp;gt;0;
		if index(format,".") = 0 then format = cats(format,".");
	run;

	*Create macro variables to be used in the data step.;
	proc sql noprint;
		select name into : variables separated by " " 
		from variables;		
		select cats(name,"_old") into : variables_old separated by " " 
		from variables;		
		select cats(name,"=",name,"_old") into : rename separated by " " 
		from variables;
		select cats(name,"=put(",name,"_old,",format,");") into : reformat separated by " " 
		from variables;
	quit;
	*Create the new data set. ;
	data &amp;amp;ds_out;
		length &amp;amp;variables $ 32;
		set &amp;amp;ds_in (rename=(&amp;amp;rename));
		&amp;amp;reformat;
		drop &amp;amp;variables_old;
	run;

%mend reformat;

*Call the format. Your data set and the output data set;
%reformat(work.class,work.class2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jul 2019 01:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/571934#M12251</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-09T01:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get value labels from SAS to Stata</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/572174#M12281</link>
      <description>This worked great! Thanks so much--you've saved me a lot of time.</description>
      <pubDate>Tue, 09 Jul 2019 18:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-value-labels-from-SAS-to-Stata/m-p/572174#M12281</guid>
      <dc:creator>bourne3rd</dc:creator>
      <dc:date>2019-07-09T18:06:07Z</dc:date>
    </item>
  </channel>
</rss>

