<?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: Subsetting and Creating new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/403030#M278615</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168982"&gt;@trash&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;It's often beneficial to code True as 1, False as 0 and everything else as Missing.&lt;/P&gt;
&lt;P&gt;If you have to differentiate between different sorts of/reasons for Missing then you can use special missing values.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p1xr9fm7y8kek5n1hpj008tnu1a1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p1xr9fm7y8kek5n1hpj008tnu1a1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code uses a custom &lt;EM&gt;informa&lt;/EM&gt;t which recodes your source values when reading into SAS.&lt;/P&gt;
&lt;P&gt;The custom &lt;EM&gt;format&lt;/EM&gt; then displays your values as True, False or Missing (do not confuse the internal values with what you see).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because True is now 1, False 0 and everything else is missing, we can simply divide the sum answers codes through&amp;nbsp;the total number of answers to&amp;nbsp;populate your proportional variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue OneZeroMiss (default=1)
    1=1
    2=0
    0=.z
    9=.n
    other=.
    ;
  value TrueFalseMiss (default=7)
    1='True'
    0='False'
    other='Missing'
    ;
run;

data work.datahw4;
  attrib group_id length=$12;
  attrib prop_pretest prop_posttest format=percent8.1;

  array pretest_  {16} 3;
  array posttest_ {14} 3;
  attrib pretest_:  format=TrueFalseMiss.;
  attrib posttest_: format=TrueFalseMiss.;

  infile 'c:\temp\DataHW4 - Copy.txt' firstobs=5 truncover;
  input 
    group_id $ 1-12 
    @59 (pretest_[*])  (OneZeroMiss1.) 
    @79 (posttest_[*]) (OneZeroMiss1.)
    ;

  prop_pretest  =sum(of pretest_[*])/dim(pretest_);
  prop_posttest =sum(of posttest_[*])/dim(posttest_);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2017 06:40:50 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-10-11T06:40:50Z</dc:date>
    <item>
      <title>Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/400251#M278611</link>
      <description>&lt;P&gt;The data set attached has 31 variables; each variable is the response to a quiz item and is coded 1=true and 2=false. Missing data are coded as either 0 or 9. The first 17 variables are responses to a pretest. After, a posttest was given.&amp;nbsp; Only the first 14 items on the pretest were repeated on the posttest, so there are a total of 31 variables (17 pretest repsonse, 14 post). One attachment is the .txt and the other is a word doc so you can see the layout slightly better.&lt;/P&gt;&lt;P&gt;1) How do I read the data into SAS and create a permanent SAS data set?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) The correct answers are:&amp;nbsp;&amp;nbsp;1. True&amp;nbsp; 2. True 3. False 4. False 5. True 6. True 7. False 8. False 9. False 10. True 11. True 12. True 13. True 14. True 15. True 16. True 17. True&lt;/P&gt;&lt;P&gt;Create two new variables, one for the proportion of correct responses on the pretest and one for the proportion of correct responses on the posttest. Missing values should be considered an incorrect answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) Conduct an appropriate summary statistics to determine whether scores on the post test or pretest were higher.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I attempted:&lt;/P&gt;&lt;P&gt;LIBNAME MyLib "D:\Statistical Data Management/MyLib";&lt;BR /&gt;data mylib.DataHW4;&lt;BR /&gt;infile 'D:\Statistical Data Management\MyLib\Homework\Assignment #4\DataHW4.txt'&lt;BR /&gt;delimiter = '09'x;&lt;BR /&gt;input ID 1-12 PreTest 59-75;&lt;BR /&gt;run;&lt;BR /&gt;data mylib.DataHW4PreTest;&lt;BR /&gt;SET mylib.dataHW4;&lt;BR /&gt;array X[1] PreTest;&lt;BR /&gt;do i=59 to 75;&lt;BR /&gt;when(1) answer = 'true';&lt;BR /&gt;when(2) answer = 'false';&lt;BR /&gt;end;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that didn't get me far, not even past number 1. Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 13:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/400251#M278611</guid>
      <dc:creator>trash</dc:creator>
      <dc:date>2017-10-02T13:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/400287#M278612</link>
      <description>&lt;P&gt;Do you&amp;nbsp;&lt;STRONG&gt;need&lt;/STRONG&gt; to decode the values?&amp;nbsp; In SAS you can apply a format to variables to display something different, e.g.:&lt;/P&gt;
&lt;PRE&gt;libname mylib "D:\Statistical Data Management/MyLib";

proc format;
  value yn
    1="true"
    2="false";
run;

data mylib.datahw4;
  infile 'D:\Statistical Data Management\MyLib\Homework\Assignment #4\DataHW4.txt' delimiter = '09'x;
  input ID 1-12 pretest 59-75;
  array pt{31};
  do i=1 to 31;
    pt{i}=input(char(pretest,i),1.);
  end;
  format pt: yn.;
run;

&lt;/PRE&gt;
&lt;P&gt;This creates a format to be applied, then in the datastep spits out each character to a 1 or 0 numeric and applies the format to all pt... variables (the : means any variable with prefix of pt).&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 14:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/400287#M278612</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-02T14:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/402747#M278613</link>
      <description>&lt;P&gt;hm okay, then how would I add a missing values statement? and since this is thought of like a quiz, no response means it is wrong. How would I write a statement for that? Would that involve creating new variables and/or subsetting?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 13:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/402747#M278613</guid>
      <dc:creator>trash</dc:creator>
      <dc:date>2017-10-10T13:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/403007#M278614</link>
      <description>proc format;&lt;BR /&gt; value yn &lt;BR /&gt;  1="true" &lt;BR /&gt;  2,.="false"; &lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;Untested. Reading the documentation is highly recommend, especially the sections explaining the basic concepts of the SAS-language.</description>
      <pubDate>Wed, 11 Oct 2017 02:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/403007#M278614</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-10-11T02:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/403030#M278615</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168982"&gt;@trash&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;It's often beneficial to code True as 1, False as 0 and everything else as Missing.&lt;/P&gt;
&lt;P&gt;If you have to differentiate between different sorts of/reasons for Missing then you can use special missing values.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p1xr9fm7y8kek5n1hpj008tnu1a1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p1xr9fm7y8kek5n1hpj008tnu1a1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code uses a custom &lt;EM&gt;informa&lt;/EM&gt;t which recodes your source values when reading into SAS.&lt;/P&gt;
&lt;P&gt;The custom &lt;EM&gt;format&lt;/EM&gt; then displays your values as True, False or Missing (do not confuse the internal values with what you see).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because True is now 1, False 0 and everything else is missing, we can simply divide the sum answers codes through&amp;nbsp;the total number of answers to&amp;nbsp;populate your proportional variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue OneZeroMiss (default=1)
    1=1
    2=0
    0=.z
    9=.n
    other=.
    ;
  value TrueFalseMiss (default=7)
    1='True'
    0='False'
    other='Missing'
    ;
run;

data work.datahw4;
  attrib group_id length=$12;
  attrib prop_pretest prop_posttest format=percent8.1;

  array pretest_  {16} 3;
  array posttest_ {14} 3;
  attrib pretest_:  format=TrueFalseMiss.;
  attrib posttest_: format=TrueFalseMiss.;

  infile 'c:\temp\DataHW4 - Copy.txt' firstobs=5 truncover;
  input 
    group_id $ 1-12 
    @59 (pretest_[*])  (OneZeroMiss1.) 
    @79 (posttest_[*]) (OneZeroMiss1.)
    ;

  prop_pretest  =sum(of pretest_[*])/dim(pretest_);
  prop_posttest =sum(of posttest_[*])/dim(posttest_);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 06:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/403030#M278615</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-11T06:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/404803#M278616</link>
      <description>&lt;P&gt;This is very helpful, thank you!!! Just one question...how does it know the correct answers? without those, the proportions would be wrong, I would think. Sorry, I'm very new to SAS!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 14:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/404803#M278616</guid>
      <dc:creator>trash</dc:creator>
      <dc:date>2017-10-17T14:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting and Creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/405163#M278617</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168982"&gt;@trash&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"...how does it know the correct answers"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The correct answers are now coded with an internal value of 1, everything else is either 0 or Missing.&amp;nbsp;With such codes we can just use the sum() function and the returned value is the number of correct answers.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 10:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-and-Creating-new-variables/m-p/405163#M278617</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-18T10:53:53Z</dc:date>
    </item>
  </channel>
</rss>

