<?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: Data Manipulation in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564604#M17345</link>
    <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the code you provided and it has worked! Even though the 'cc' variable that was created by the array turned out to be binary '0' and '1' instead of a count variable, I can still use that in my analysis since the proportion of records with any of the comorbid conditions of interest to me is just 2.42%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Sat, 08 Jun 2019 01:23:06 GMT</pubDate>
    <dc:creator>Rahim9</dc:creator>
    <dc:date>2019-06-08T01:23:06Z</dc:date>
    <item>
      <title>Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564520#M17336</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to this community. I need help manipulating my data in order to conduct an analysis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is a trauma records data, it contains up to 65 variables for every patient who sustained a trauma and was captured in the registry. I am conducting an analysis to identify association between certain factors (gender, race, and insurance status) and risk of death. However, In my multivariate logistic regression model, I need to control for comorbid conditions. The dataset has 5 columns (variables) for comorbid conditions for each patient in the record. These comorbid variables are coded as character variables such as "epilepsy seizures" "dementia" "osteoporosis" etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is to get SAS to search each of those five comorbid variables for the presence of any of selected conditions (30 in number) that I would provide. SAS should then create a count variable that will indicated the number of comorbid conditions present on each patient. (0 to 30).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is basically how my data looks like:&lt;/P&gt;&lt;P&gt;record_id&amp;nbsp; &amp;nbsp;comorbid_1&amp;nbsp; &amp;nbsp;comorbid_2&amp;nbsp; &amp;nbsp; comorbid_3&amp;nbsp; &amp;nbsp;comorbid_4&amp;nbsp; &amp;nbsp; comorbid_5&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dementia&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pulmonary_disorder&amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;osteoporosis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dementia&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; prostate cancer&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hepatitis&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pacemaker&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dementia&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this is a lengthy post, I really would appreciate any help.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 17:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564520#M17336</guid>
      <dc:creator>Rahim9</dc:creator>
      <dc:date>2019-06-07T17:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564522#M17337</link>
      <description>You need an array and a loop to search through the items.</description>
      <pubDate>Fri, 07 Jun 2019 17:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564522#M17337</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-07T17:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564524#M17338</link>
      <description>&lt;P&gt;Thank you for your response. Any suggestion on how to code Array and Loop?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 18:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564524#M17338</guid>
      <dc:creator>Rahim9</dc:creator>
      <dc:date>2019-06-07T18:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564526#M17339</link>
      <description>&lt;P&gt;This paper covers using arrays to search for diagnosis and shows how to convert your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings16/5720-2016.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings16/5720-2016.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266994"&gt;@Rahim9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your response. Any suggestion on how to code Array and Loop?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 18:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564526#M17339</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-07T18:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564530#M17340</link>
      <description>&lt;P&gt;I will look at it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 18:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564530#M17340</guid>
      <dc:creator>Rahim9</dc:creator>
      <dc:date>2019-06-07T18:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564531#M17341</link>
      <description>&lt;P&gt;Not really a long post, so no worries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It helps to provide data in the form of a data step so we have something to code against. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way that may&amp;nbsp; get you started. The data step is an example of turning your pasted text into a data step that can create usable data.&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines dlm=',' dsd truncover;
informat record_id   comorbid_1   comorbid_2    comorbid_3   comorbid_4    comorbid_5 $25.;
input record_id   comorbid_1   comorbid_2    comorbid_3   comorbid_4    comorbid_5;
datalines;
1,dementia,,,pulmonary_disorder,
2,,osteoporosis,dementia,,prostate cancer
3, hepatitis,,pacemaker,dementia,
;

data want;
   set have;
   array words{5} $25 _temporary_ ('dementia','pulmonary_disorder','osteoporosis','hepatitis','pacemaker');
   array c comorbid_:;
   cc=0;
   do i= 1 to dim(words);
      cc= cc+ (whichc(words[i], of c(*))&amp;gt;0);
   end;
   drop i;
   label cc='Comorbidity count';
run;&lt;/PRE&gt;
&lt;P&gt;Some things that a new SAS user will not recognize right away.&lt;/P&gt;
&lt;P&gt;The first array, WORDS, contains values that will 1) disappear at the end of the data step, that's what the _temporary_ means, 2) sets the initial (and not changed values) in the (). The number in the {} is how many values you need this has to be large enough to match the number of actual terms you need. The $25 says that the array will hold character values and how long each is. This needs to be at least as long as the longest value you need to search for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We set the value to 0 before starting the search.&lt;/P&gt;
&lt;P&gt;The WHICHC function will search for the first parameter, the current item as we loop through the list of words, and if found in any of the elements contained in the second array c returns which position, 1 to 5 in this case if found or 0 if not found. The comparison of &amp;gt;1 creates a 1 when any match is found so we can add that to the counter variable CC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Things to consider: if your data entry isn't clean and has values like :Dementia, dementia or dEMENTIA you may want to UPCASE all of the array values so case is not an issue as "dementia" will not match "Dementia" in the WHICHC values.&lt;/P&gt;
&lt;P&gt;Second if you have spelling issues: "demensia" for instance, you likely want to fix those first OR you end up with many more values in the WORDS array to include all of the different spellings.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 18:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564531#M17341</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-07T18:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564532#M17342</link>
      <description>&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is very helpful. I will study it and get back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 18:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564532#M17342</guid>
      <dc:creator>Rahim9</dc:creator>
      <dc:date>2019-06-07T18:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564604#M17345</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the code you provided and it has worked! Even though the 'cc' variable that was created by the array turned out to be binary '0' and '1' instead of a count variable, I can still use that in my analysis since the proportion of records with any of the comorbid conditions of interest to me is just 2.42%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jun 2019 01:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Data-Manipulation/m-p/564604#M17345</guid>
      <dc:creator>Rahim9</dc:creator>
      <dc:date>2019-06-08T01:23:06Z</dc:date>
    </item>
  </channel>
</rss>

