<?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: Scanning multiple variables to create new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457824#M284476</link>
    <description>&lt;P&gt;That worked!! Thank you!!&lt;/P&gt;</description>
    <pubDate>Thu, 26 Apr 2018 17:20:54 GMT</pubDate>
    <dc:creator>erich20</dc:creator>
    <dc:date>2018-04-26T17:20:54Z</dc:date>
    <item>
      <title>Scanning multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457813#M284472</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that contains patient id numbers and 22 drug id value columns (DrugID1 - DrugID22) for a large patient population. I'm trying to create a new variable for the dataset that indicates if and how often a specific id number "40" is observed for each patient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my code to run so that SAS scans all of the drug id numbers for each patient and outputs the following in a new column:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0 - if the id value "40" was not identified in any of the patient's 22 drug id numbers&lt;/P&gt;&lt;P&gt;1 - if the id value "40" was identified in exactly one of the patient's 22 drug id numbers&lt;/P&gt;&lt;P&gt;2 - if the id value "40" was identified in more than one of the patient's 22 drug id numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 16:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457813#M284472</guid>
      <dc:creator>erich20</dc:creator>
      <dc:date>2018-04-26T16:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457815#M284473</link>
      <description>&lt;P&gt;The easiest way would be create an array to hold all of your drug IDs and then loop through and count how many are equal to the specific drug ID you're looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
   input ID DrugID1 DrugID2;
datalines;
1 40 57
2 40 40
;
run;

data temp2;
   set temp;
   by id;

   if first.id then count=0;

   array drugs {*} DrugID:;
   do i = 1 to dim(drugs);
      count + (drugs[i]=40);
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 16:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457815#M284473</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2018-04-26T16:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457817#M284474</link>
      <description>&lt;P&gt;Something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array drugs {*} drugid1-drugid22;
flag = 0;
do i = 1 to dim(drugs);
  flag + (index(drugs{i},'40') &amp;gt; 0);
end;
if flag &amp;gt; 2 then flag = 2;
drop i;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 16:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457817#M284474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-26T16:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457819#M284475</link>
      <description>Thank you for the quick response!&lt;BR /&gt;&lt;BR /&gt;I haven't create arrays before so I have a couple questions....&lt;BR /&gt;&lt;BR /&gt;The data set I'm working with also contains a lot of other variables that I&lt;BR /&gt;want to keep (e.g. bmi, age, sex, etc). When creating the temp dataset as&lt;BR /&gt;seen in your code can I just set my dataset (which is titled "final_drug")&lt;BR /&gt;instead of using the input function?&lt;BR /&gt;&lt;BR /&gt;If yes, then do I still include the datalines function?&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;&lt;BR /&gt;*More information:*&lt;BR /&gt;&lt;BR /&gt;Name of data set : Final_drug;&lt;BR /&gt;Name of patient id variable: seqn;&lt;BR /&gt;Name of drug id variables: drugID1, drugID2, drugID3,..., drugID22&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Apr 2018 17:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457819#M284475</guid>
      <dc:creator>erich20</dc:creator>
      <dc:date>2018-04-26T17:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457824#M284476</link>
      <description>&lt;P&gt;That worked!! Thank you!!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 17:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457824#M284476</guid>
      <dc:creator>erich20</dc:creator>
      <dc:date>2018-04-26T17:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Scanning multiple variables to create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457829#M284477</link>
      <description>&lt;P&gt;I created dataset temp just to have some data to illustrate my point. The input statement tells SAS what to read in from the data lines I will be providing and the datalines statement start off the listing of the raw data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code would have only one DATA step and should look similar to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Final_drug_counts;
   set Final_drug;
   by seqn;

   if first.seqn then count=0;

   array drugs {*} DrugID:;
   do i = 1 to dim(drugs);
      count + (drugs[i]=40);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your other variables will remain in the dataset, unchanged.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 17:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Scanning-multiple-variables-to-create-new-variable/m-p/457829#M284477</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2018-04-26T17:22:43Z</dc:date>
    </item>
  </channel>
</rss>

