<?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: Create an enumeration variable with a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253909#M48354</link>
    <description>&lt;P&gt;Thank you so much for your help. This code worked!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All I needed to do was add&amp;nbsp;&lt;STRONG&gt;(*)&amp;nbsp;&lt;/STRONG&gt;to the ARRAY statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt; array q&amp;nbsp;&lt;STRONG&gt;(*) &amp;nbsp;&lt;/STRONG&gt;q1-q10&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2016 18:35:40 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2016-03-02T18:35:40Z</dc:date>
    <item>
      <title>Create an enumeration variable with a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253638#M48297</link>
      <description>&lt;P&gt;I need to create a new variable (count_var) that counts the number of questions that were left unanswered in a survey. The value of an unanswered question is 0. There are 10 questions in the survey.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, the value of count_var will equal the number of unanswered questions for each subject.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was not abCreate an enumeration variable with a condition" post in this forum.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your&amp;nbsp;&lt;SPAN class="s1"&gt;assistance&lt;/SPAN&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 23:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253638#M48297</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-01T23:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create an enumeration variable with a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253707#M48305</link>
      <description>Are each question/answer on separate observations? &lt;BR /&gt;&lt;BR /&gt;Proc sql; &lt;BR /&gt;Create table want as&lt;BR /&gt;Select survey, subject, count (*) as count_var&lt;BR /&gt;From have&lt;BR /&gt;Where answer is null;&lt;BR /&gt;Quit;</description>
      <pubDate>Wed, 02 Mar 2016 07:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253707#M48305</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-02T07:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create an enumeration variable with a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253725#M48308</link>
      <description>&lt;P&gt;Please post sample test data (in the form of a datastep) and required output otherwise code will just be guessing.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 09:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253725#M48308</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-02T09:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create an enumeration variable with a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253872#M48343</link>
      <description>&lt;P&gt;If the values for non-answered had been treated as MISSING instead of assigned a value this would be trivial with the CMISS function.&lt;/P&gt;
&lt;P&gt;I strongly recommend considering use of missing values instead of 0 as you cannot expect to get really accurate values for things like "average response" or most statistics with your current coding.&lt;/P&gt;
&lt;P&gt;However Assuming the values are 1) actually numeric 2) one observation per respondent then something like&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; array q q1-q10; /* assumes the questions are named Q1 Q2 etc. put list of actual names if significantly different*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Count_var=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do i=1 to dim(q);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count_var= count_var + (q[i] = 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; drop i;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your variables are actually character then use = "0".&lt;/P&gt;
&lt;P&gt;If we knew the range of of the responses it might be possible to get the result in a single line use COUNTC and a contactenation of the values, but insufficient information of the values was provided.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 16:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253872#M48343</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-02T16:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create an enumeration variable with a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253905#M48352</link>
      <description>&lt;P&gt;&amp;lt;&lt;SPAN&gt;Are each question/answer on separate observations?&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes, there are 10 questions. The values of the observations can be between 0 and 3.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm a relatively novice SAS user and have never used PROC SQL. A few clarifying questions:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;lt;Create table want as&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is&amp;nbsp;creating a table with the desired items? What does the "as" command do?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;&lt;SPAN&gt;Select survey, subject, count (*) as count_var&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Is survey a list of variables that make up the survey?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;SPAN&gt;Where answer is null;&amp;gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;How does SAS define "null"?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanks!!!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 18:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253905#M48352</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-02T18:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create an enumeration variable with a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253909#M48354</link>
      <description>&lt;P&gt;Thank you so much for your help. This code worked!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All I needed to do was add&amp;nbsp;&lt;STRONG&gt;(*)&amp;nbsp;&lt;/STRONG&gt;to the ARRAY statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt; array q&amp;nbsp;&lt;STRONG&gt;(*) &amp;nbsp;&lt;/STRONG&gt;q1-q10&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 18:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-an-enumeration-variable-with-a-condition/m-p/253909#M48354</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-02T18:35:40Z</dc:date>
    </item>
  </channel>
</rss>

