<?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 How to permanently format many coded variables efficiently in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304720#M64872</link>
    <description>&lt;P&gt;Hi all. I would like to permanently replace coded values with their&amp;nbsp;formatted values. The catch is my dataset has 50+&amp;nbsp;variables that need formatting. I can only think of two ways to do this and both require lots of&amp;nbsp;repetitive coding: 1) use the put function 2) use SQL with put function (at least with SQL I don't have to rename the variable, create a new one, and drop the old one). Does anyone have any other solutions? Perhaps there is a way to use the put function with&amp;nbsp;multiple variables? Or perhaps there is another SAS function that can help? Here is some dummy code to play with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input x1 x2 x3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 2&lt;BR /&gt;3 2 1&lt;BR /&gt;3 3 3&lt;BR /&gt;1 2 1&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value x1f 1='a' 2='b' 3='c';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value x2f 1='d' 2='e' 3='f';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value x3f 1='g' 2='h' 3='i';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data wantDS;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set have(rename=(x1=x1c x2=x2c x3=x3c));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x1=put(x1c,x1f.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x2=put(x2c,x2f.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x3=put(x3c,x3f.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drop x1c x2c x3c;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table wantSQL as&lt;BR /&gt;select put(x1,x1f.) as x1, &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; put(x2,x2f.) as x2, &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; put(x3,x3f.) as x3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;from have;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2016 18:38:45 GMT</pubDate>
    <dc:creator>spirto</dc:creator>
    <dc:date>2016-10-14T18:38:45Z</dc:date>
    <item>
      <title>How to permanently format many coded variables efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304720#M64872</link>
      <description>&lt;P&gt;Hi all. I would like to permanently replace coded values with their&amp;nbsp;formatted values. The catch is my dataset has 50+&amp;nbsp;variables that need formatting. I can only think of two ways to do this and both require lots of&amp;nbsp;repetitive coding: 1) use the put function 2) use SQL with put function (at least with SQL I don't have to rename the variable, create a new one, and drop the old one). Does anyone have any other solutions? Perhaps there is a way to use the put function with&amp;nbsp;multiple variables? Or perhaps there is another SAS function that can help? Here is some dummy code to play with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input x1 x2 x3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 2&lt;BR /&gt;3 2 1&lt;BR /&gt;3 3 3&lt;BR /&gt;1 2 1&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value x1f 1='a' 2='b' 3='c';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value x2f 1='d' 2='e' 3='f';&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value x3f 1='g' 2='h' 3='i';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data wantDS;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set have(rename=(x1=x1c x2=x2c x3=x3c));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x1=put(x1c,x1f.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x2=put(x2c,x2f.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;x3=put(x3c,x3f.);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drop x1c x2c x3c;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table wantSQL as&lt;BR /&gt;select put(x1,x1f.) as x1, &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; put(x2,x2f.) as x2, &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; put(x3,x3f.) as x3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;from have;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2016 18:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304720#M64872</guid>
      <dc:creator>spirto</dc:creator>
      <dc:date>2016-10-14T18:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to permanently format many coded variables efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304725#M64874</link>
      <description>&lt;P&gt;If you have a format then you assign it to the variable. Put will create additional text variables. If you need the format permanently attached then use a format statement in a data step (preferrably the first step involving the variables) or use Proc datasets to assign the format.&lt;/P&gt;
&lt;P&gt;Example of the first:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
    value x1f 1='a' 2='b' 3='c';
    value x2f 1='d' 2='e' 3='f';
    value x3f 1='g' 2='h' 3='i';
run;

data have;
    input x1 x2 x3;
    format x1 x1F. x2 x2f.  x3 x3f.;
datalines;
1 1 2
3 2 1
3 3 3
1 2 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets;
   modify  have  ;
      format x1 x1F. x2 x2f.  x3 x3f.;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Oct 2016 17:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304725#M64874</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-10-14T17:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to permanently format many coded variables efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304837#M64925</link>
      <description>&lt;P&gt;You could use code-writing code. Assuming format names derived from variable names, as in your example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename recode temp;

data _null_;
file recode;
put "data wamt; set have;";
do v = "x1", "x2", "x3";
    w = cats(v, "c");
    f = cats(v, "f.");
    put w "= put(" v "," f "); rename " w "=" v "; drop " v ";";
    end;
put "run;";
run; 

%include recode / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you could also create a table of variable names and formats and have a _null_ step write code from those.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2016 03:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-permanently-format-many-coded-variables-efficiently/m-p/304837#M64925</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-15T03:27:15Z</dc:date>
    </item>
  </channel>
</rss>

