<?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: Count number options in different questionnaire options in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915233#M40961</link>
    <description>&lt;P&gt;Please run PROC CONTENTS on your data and tell us if these two variables are numeric or character. The variable could be numeric and the Z and N could be coded as missing values .N and .Z.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So really impossible to answer at this time without your PROC CONTENTS results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I run PROC CONTENTS on data set SASHELP.CARS, I get this, and you can see that some variables are Num (numeric) and others are Char (character):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1706795071831.png" style="width: 431px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93151i7577EC6C8BA97B2C/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1706795071831.png" alt="PaigeMiller_0-1706795071831.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Feb 2024 13:46:13 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-02-09T13:46:13Z</dc:date>
    <item>
      <title>Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915225#M40960</link>
      <description>&lt;P&gt;Hi. In same data A, I would like to count those who answer the number of days to each question for the use of cigarette or marijuana which can range from 0-30 in QN1 and QN2, and code them into any_user . Please note apart from any number from 0 to 3 there are character options to question stem such as 'N' for not answered and 'Z' for skipped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;QN1: During the past 30 days, on how many days did you use e-cigarettes?&lt;/P&gt;
&lt;P&gt;N&lt;/P&gt;
&lt;P&gt;Z&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;QN2: During the past 30 days, on how many days did you use marijuana?&lt;/P&gt;
&lt;P&gt;N&lt;/P&gt;
&lt;P&gt;Z&lt;/P&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;Data A,
if QN1 in (1-30) or QN2 in (1-30) then any_sub_user=1;
else any_sub_user=2;
run;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Feb 2024 13:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915225#M40960</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-09T13:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915233#M40961</link>
      <description>&lt;P&gt;Please run PROC CONTENTS on your data and tell us if these two variables are numeric or character. The variable could be numeric and the Z and N could be coded as missing values .N and .Z.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So really impossible to answer at this time without your PROC CONTENTS results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I run PROC CONTENTS on data set SASHELP.CARS, I get this, and you can see that some variables are Num (numeric) and others are Char (character):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1706795071831.png" style="width: 431px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93151i7577EC6C8BA97B2C/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1706795071831.png" alt="PaigeMiller_0-1706795071831.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 13:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915233#M40961</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-09T13:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915234#M40962</link>
      <description>What does PROC CONTENTS tell you about QN1 and QN2?  Are they character or are they numeric?</description>
      <pubDate>Fri, 09 Feb 2024 13:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915234#M40962</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-02-09T13:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915247#M40964</link>
      <description>Both QN1 and QN2 are numeric variables&lt;BR /&gt;&lt;BR /&gt;type (Num), Len (8), Format (BEST.)</description>
      <pubDate>Fri, 09 Feb 2024 14:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915247#M40964</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-09T14:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915249#M40965</link>
      <description>They are numeric variables (proc contents). Please note am recoding with "OR" to capture in any of the QN where a any numeric from 1 to 30  is mentioned</description>
      <pubDate>Fri, 09 Feb 2024 14:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915249#M40965</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-09T14:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915251#M40966</link>
      <description>&lt;P&gt;With numeric variables, you can't use 1-30 (SAS sees this as subtraction). However, you can use a simple&amp;nbsp;arithmetic test to see if the number is between 1 and 30.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if 1&amp;lt;=QN1&amp;lt;=30 or 1&amp;lt;=QN1&amp;lt;=30 then any_sub_user=1;
    else any_sub_user=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 14:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915251#M40966</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-09T14:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915260#M40967</link>
      <description>&lt;P&gt;Your syntax for the IN operator is wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data q;
   missing N Z;
   input qn1 qn2;
   if QN1 in (1:30) or QN2 in (1:30) 
      then any_sub_user=1;
      else any_sub_user=0;

   cards;
N 3
Z 0
0 N
1 0
2 Z
3 1
;;;;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 185px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93467iFF8F9A68E432CD52/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 14:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915260#M40967</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-02-09T14:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915297#M40968</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436402"&gt;@femiajumobi1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. In same data A, I would like to count those who answer the number of days to each question for the use of cigarette or marijuana which can range from 0-30 in QN1 and QN2, and code them into any_user .&lt;/P&gt;
&lt;P&gt;(...)&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;Data A,
if QN1 in (1-30) or QN2 in (1-30) then any_sub_user=1;
else any_sub_user=2;
run;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Alternative solution:&lt;/P&gt;
&lt;P&gt;Obviously, you just want to distinguish between positive numbers and zero or missing values in QN1 and QN2. Since negative values do not occur, this amounts to interpreting QN1 and QN2 as Boolean values and the (corrected) IF condition boils down to the Boolean expression&amp;nbsp;&lt;FONT face="courier new,courier"&gt;QN1 | QN2&lt;/FONT&gt;. Using the definition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;any_sub_user = QN1 | QN2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the sum of variable &lt;FONT face="courier new,courier"&gt;any_sub_user&lt;/FONT&gt; would yield the desired count (as&amp;nbsp;the numeric values of TRUE and FALSE are 1 and 0, respectively). Similarly, if you really need the value 2 in the "ELSE" case, you can define&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;any_sub_user = 2-(QN1 | QN2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the above definitions are still valid if the time span is changed to fewer or more than 30 days and also if non-integer responses (such as 1.5) are accepted.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 15:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915297#M40968</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-09T15:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count number options in different questionnaire options</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915301#M40969</link>
      <description>This works. Super-efficient codes. Thanks.</description>
      <pubDate>Fri, 09 Feb 2024 15:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-number-options-in-different-questionnaire-options/m-p/915301#M40969</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-09T15:58:18Z</dc:date>
    </item>
  </channel>
</rss>

