<?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 Formatting of all binary variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838493#M331517</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I would like to select all binary 0/1 variables from my dataset and apply yesno. format to them.&lt;/P&gt;
&lt;P&gt;All suggestions are welcome.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 13 Oct 2022 19:05:34 GMT</pubDate>
    <dc:creator>pink_poodle</dc:creator>
    <dc:date>2022-10-13T19:05:34Z</dc:date>
    <item>
      <title>Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838493#M331517</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I would like to select all binary 0/1 variables from my dataset and apply yesno. format to them.&lt;/P&gt;
&lt;P&gt;All suggestions are welcome.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 19:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838493#M331517</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-10-13T19:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838498#M331522</link>
      <description>&lt;P&gt;Either write a custom format using Proc Format or simple if-then-else logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depends on the situation. Post more information if you want a more detailed answer.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 19:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838498#M331522</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-13T19:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838499#M331523</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format variablename1 variablename2 variablename3 yesno.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where obviously, you have to type in the actual variable names in your data set, or use a valid SAS list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format x1-x27 yesno.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Oct 2022 19:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838499#M331523</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-13T19:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838510#M331534</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235176"&gt;@pink_poodle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I would like to select all binary 0/1 variables from my dataset and apply yesno. format to them.&lt;/P&gt;
&lt;P&gt;All suggestions are welcome.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this code supposed to examine your data set, find variables that only have 1 and 0 values? What if the values are missing for some records? What if the value is character '1' and '0'? What if one or more of the variables that your are thinking are 0/1 only have 0 for a value? Or only 1 for a value?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2022 20:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838510#M331534</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-13T20:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838759#M331636</link>
      <description>That is right. My intention was to find all binary variables in the dataset and then apply the yesno format to them. Usually they are numeric 0/1. I kind of found a not-so-elegant way of Find-Replacing them in Word reports, but am still curious about achieving this task before the output to Word.</description>
      <pubDate>Fri, 14 Oct 2022 23:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838759#M331636</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-10-14T23:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838778#M331648</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Identify numeric variables (DICTIONARY.COLUMNS)&lt;/LI&gt;
&lt;LI&gt;Run PROC FREQ on all of them, use OUT= to create a dataset&lt;/LI&gt;
&lt;LI&gt;Analyze the dataset to find all those that have only the two values, and store their names in a macro variable&lt;/LI&gt;
&lt;LI&gt;Use the macro variable in PROC DATASETS&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Sat, 15 Oct 2022 05:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838778#M331648</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-15T05:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838784#M331652</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;UL&gt;
&lt;LI&gt;Identify numeric variables (DICTIONARY.COLUMNS)&lt;/LI&gt;
&lt;LI&gt;Run PROC FREQ on all of them, use OUT= to create a dataset&lt;/LI&gt;
&lt;LI&gt;Analyze the dataset to find all those that have only the two values, and store their names in a macro variable&lt;/LI&gt;
&lt;LI&gt;Use the macro variable in PROC DATASETS&lt;/LI&gt;
&lt;/UL&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Proc freq with the NLELEVLS may be useful as well.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data example;
   input var1 $ var2 var3 var4 var5;
datalines;
1 1 0 1 1
b 0 0 0 1
1 1 1 1 2
b 0 1 1 0
;

proc freq data=example nlevels ;
   ods output nlevels=levelset;
   tables _numeric_;
run;&lt;/PRE&gt;
&lt;P&gt;The data set Levelset will have the variable name along with the number of levels the variables have in the Nlevels variable.&lt;/P&gt;
&lt;P&gt;So any variable with Nlevels &amp;gt; 2 could be excluded from further processing though confirmation that the values. Coupled with a Proc Means data set built with STACKODS and Min / Max the process for numeric values can be pretty straightforward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input var1 $ var2 var3 var4 var5;
datalines;
1 1 0 1 1
b 0 0 0 1
1 1 1 1 2
b 0 1 1 0
;

proc freq data=example nlevels ;
   ods output nlevels=levelset (rename=(tablevar = variable)) ;
   tables _numeric_;
run;

Proc means data=example stackodsoutput min max;
   ods output summary=summaryset;
   var _numeric_;
run;

data want;
   merge levelset
         summaryset
   ;
   by variable;
   if nlevels=2 and min=0 and max=1;
run;&lt;/PRE&gt;
&lt;P&gt;The Want data set has one row for each variable that has exactly 2 levels of values with the minimum=0 and maximum=1.&lt;/P&gt;
&lt;P&gt;So you can select the variables names how you want such as a list created here that could be used in a format statement like&lt;/P&gt;
&lt;P&gt;Format &amp;amp;varlist. yesno. ; as needed/&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select variable into :varlist separated by ' '
   from want
   ;
quit;
%put Variable list is: &amp;amp;varlist. ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2022 05:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838784#M331652</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-15T05:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838817#M331661</link>
      <description>Could you please elaborate on the fourth point about PROC DATASETS?</description>
      <pubDate>Sat, 15 Oct 2022 13:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838817#M331661</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-10-15T13:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting of all binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838828#M331669</link>
      <description>&lt;P&gt;I recommend you study the documentation of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1hmips60w5w3yn1hj9klna7aplw.htm" target="_blank" rel="noopener"&gt;DATASETS Procedure&lt;/A&gt;, particularly the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n0ahh0eqtadmp3n1uwv55i2gyxiz.htm" target="_blank" rel="noopener"&gt;MODIFY Statemen&lt;/A&gt;t, where you use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n09nl7f8smat49n1rz1rav5i6a8a.htm" target="_blank" rel="noopener"&gt;FORMAT Statement&lt;/A&gt;&amp;nbsp;as usual.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2022 17:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-of-all-binary-variables/m-p/838828#M331669</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-15T17:26:37Z</dc:date>
    </item>
  </channel>
</rss>

