<?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: Not sure how to summarize my question... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654674#M196596</link>
    <description>&lt;P&gt;A better question may be "Why do you need 4 variables?".&lt;/P&gt;
&lt;P&gt;One of the typical uses of what you are requesting is to use the 1/0 coded values as "dummy" or "indicator" variables in regression analysis. Most of the SAS regression procedures will allow you to place your Response variable on a CLASS statement so that when it is used in the Model the levels are created as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And another way&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue AA
'A'=1
other=0
;
invalue BB
'B'=1
other=0
;
invalue CC
'C'=1
other=0
;
invalue DD
'D'=1
other=0
;
run;

data example;
   input response $;
   a = input(response,aa.);
   b = input(response,bb.);
   c = input(response,cc.);
   d = input(response,dd.);
datalines;
A
D
B
C
;&lt;/PRE&gt;
&lt;P&gt;The informats have a 2 character name because a single D will conflict with a SAS supplied informat, or at least that was the error I got. So make them all similar in name with 2 characters.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jun 2020 20:13:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-08T20:13:16Z</dc:date>
    <item>
      <title>Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654661#M196586</link>
      <description>&lt;P&gt;I am trying to create 4 new variables(var_A, Var_B, Var_C, Var_D).&amp;nbsp; Where Var_A has a value of 1 if Response is A, and a value of 0 otherwise.&amp;nbsp; And Var_B has a value of 1 if Response is B , and a value of 0 otherwise.&amp;nbsp; Likewise for C and D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done it the following 2 ways, and am wondering if there is a built in function for such a process.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** Way 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Table1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set Table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if Response = "A" then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var_A = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if Response = "B" then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var_B = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if Response = "C" then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var_C = 1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if Response = "D" then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var_D = 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*macros to add zeros to the non 1 places from above*/&lt;BR /&gt;%LET List= A B C D;&lt;/P&gt;&lt;P&gt;%Macro Zeros();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; data Table1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; set Table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if Var_&amp;amp;MM. ^= 1 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var_&amp;amp;MM. = 0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%MEND Zeros;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Macro Loop_M();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%DO M=1 %TO 4;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%LET MM=%SCAN(&amp;amp;List., &amp;amp;M.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%Zeros();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%END;&lt;BR /&gt;%MEND Loop_M;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Var_M();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** Way 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Table1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set Table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if Response = "A" then do&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var_A=1; Var_B=0; Var_C=0; Var_D=0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if Response = "B" then do&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var_B=1; Var_A=0; Var_C=0; Var_D=0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if Response = "C" then do&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var_C=1; Var_A=0; Var_B=0; Var_D=0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if Response = "D" then do&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var_D=1; Var_A=0; Var_B=0; Var_C=0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else do&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var_A=0; Var_B=0; Var_C=0; Var_D=0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an easier way to accomplish this?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 19:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654661#M196586</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2020-06-08T19:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654666#M196591</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Table1;
     set Table;
          Var_A=0; Var_B=0; Var_C=0; Var_D=0;
         if Response = "A" then do
              Var_A=1;
        end;
        else if Response = "B" then do
              Var_B=1;
        end;
        else if Response = "C" then do
              Var_C=1; 
        end;
        else if Response = "D" then do
              Var_D=1; 
        end;
       
run;

Data Table1;
     set Table;
          
        Var_A = 1* (Response='A');
         Var_B = 1* (Response='B');
         Var_C = 1* (Response='C');
           Var_D = 1* (Response='D');
     
        
       
run;

Data Table1;
     set Table;
        %let i = 1 %to 4;
            %let varlst = A B C D;
            %let var=%scan(&amp;amp;varlst.,&amp;amp;i.);
              Var_&amp;amp;var.= 1* (Response="&amp;amp;var."); 
        %end;  
             
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Three ways hown above&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 19:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654666#M196591</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-08T19:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654668#M196592</link>
      <description>&lt;P&gt;It could be done with arrays, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array responses(4) $1 _temporary_ ('A','B','C','D');
  array vars(4) 8 Var_A Var_B Var_C Var_D;
  do _N_=1 to dim(vars);
    vars(_N_)=(Response=responses(_N_));
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jun 2020 20:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654668#M196592</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-08T20:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654673#M196595</link>
      <description>&lt;P&gt;SAS has built-in ways to create 0/1 (sometimes called "dummy" variables) so you don't have to program it yourself (and risk getting it wrong). One method is PROC GLMMOD, but there are many other methods as discussed in this thread&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-dummy-variables-Categorical-Variables/ta-p/308484" target="_blank"&gt;How to create dummy variables - Categorical Variables&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, many SAS procedures allow you to use a CLASS statement, so the 0/1 variables are created by the PROC internally, so you don't have to create them at all. Please consider this approach, as it is the least painful and least error-prone method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I guess the real question is, what are you going to do with these 0/1 variables once you create them?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 20:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654673#M196595</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-08T20:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654674#M196596</link>
      <description>&lt;P&gt;A better question may be "Why do you need 4 variables?".&lt;/P&gt;
&lt;P&gt;One of the typical uses of what you are requesting is to use the 1/0 coded values as "dummy" or "indicator" variables in regression analysis. Most of the SAS regression procedures will allow you to place your Response variable on a CLASS statement so that when it is used in the Model the levels are created as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And another way&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue AA
'A'=1
other=0
;
invalue BB
'B'=1
other=0
;
invalue CC
'C'=1
other=0
;
invalue DD
'D'=1
other=0
;
run;

data example;
   input response $;
   a = input(response,aa.);
   b = input(response,bb.);
   c = input(response,cc.);
   d = input(response,dd.);
datalines;
A
D
B
C
;&lt;/PRE&gt;
&lt;P&gt;The informats have a 2 character name because a single D will conflict with a SAS supplied informat, or at least that was the error I got. So make them all similar in name with 2 characters.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 20:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654674#M196596</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-08T20:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654675#M196597</link>
      <description>&lt;P&gt;I believe you didn't intent to use _n_;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 20:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/654675#M196597</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-08T20:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/655490#M196643</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input response $;
cards;
A
B
C
D
;
data temp(rename=(response=var_));
 set have;
 y=1;
run;
proc logistic data=temp outdesign=design(drop=y) outdesignonly;
class var_ / param=glm ;
model y=var_/nofit noint;
run;
data want;
 merge have design;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jun 2020 12:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/655490#M196643</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-09T12:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to summarize my question...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/655608#M196694</link>
      <description>I really liked that 2nd way. I never thought of doing it like that.</description>
      <pubDate>Tue, 09 Jun 2020 17:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-summarize-my-question/m-p/655608#M196694</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2020-06-09T17:58:19Z</dc:date>
    </item>
  </channel>
</rss>

