<?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: Making groups for different outcomes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784168#M250194</link>
    <description>&lt;P&gt;So only the first change matters when you do this grouping?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a patient has 1--&amp;gt;2--&amp;gt;3, this patient still is in the 1-&amp;gt;2 group?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length group $ 6;
    array lead lead:;
    if range(of lead:)=0 then group=put(lead_1,6. -l);
    else do i=2 to dim(lead);
        if lead(i)^=lead(i-1) then do;
            group=cats(lead(i-1),'-&amp;gt;',lead(i));
            leave;
        end;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 05 Dec 2021 12:42:57 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-12-05T12:42:57Z</dc:date>
    <item>
      <title>Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784091#M250142</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a column with subjects (called record_id) and a list of variables (called lead_1, lead_2, lead_3 and soforth).&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the variable lead_x, its only possible to have the values: 1, 2, 99 or none present.&amp;nbsp;&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="JT9_0-1638635504803.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66406i66B1F13C3B049C4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JT9_0-1638635504803.png" alt="JT9_0-1638635504803.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I would like to make groups of subjects and count these groups, according to&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;- how many is presented with a value "1" in all lead_types (from left to right),&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;- how many with the value 2 in all lead_types,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;- how many is starting with 1 in som lead_types and then changes to lead_2 and vice verca&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;- how many is starting in group 99, changing to 1 and later 2&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;- and so on for possible variation outcomes&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;In summary I would like the number of subjects in all possible variations. Its only interesting for me, WHEN they change group&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this (first part to extract the needed information in one set called gr and then proc freq to see the outcomes and number in each group):&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data gr; 
set lead_c; 
group = cat(lead_1,lead_2,lead_3,lead_4,lead_5,lead_6,lead_7,lead_8,lead_9,lead_10,lead_11,lead_12,lead_13,lead_14,lead_15);
run; 

proc freq data=gr; 
	tables group; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which gives me (part is shown below):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JT9_1-1638635904811.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66407i67D07F5EAE45750C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JT9_1-1638635904811.png" alt="JT9_1-1638635904811.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here I would like SAS to read the previous number and only classify the ID when they change number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need som retain statement&amp;nbsp; and a way to imply to ignore, if empty to get free of all those "...."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone who can help how to get closer to the solution ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 16:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784091#M250142</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-04T16:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784092#M250143</link>
      <description>&lt;P&gt;We can't work with data that is a screen capture. We need (a portion of) your data presented in SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;) and not via any other method or format.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 17:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784092#M250143</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-04T17:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784096#M250145</link>
      <description>I made a miniature version of dataset&lt;BR /&gt;&lt;BR /&gt;Hope this works out&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input s_id lead_1 lead_2 lead_3 lead_4 lead_5 lead_6 lead_7;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1 1 1 1 1&lt;BR /&gt;2 1 1 1 3 3 3 3&lt;BR /&gt;3 1 1 1 1 1 2 2&lt;BR /&gt;4 1 2 2 2 2 2 2&lt;BR /&gt;5 1 1 1 1 2 2 2&lt;BR /&gt;6 1 1 1 1 1 1 1&lt;BR /&gt;7 2 2 2 2 2 1 2&lt;BR /&gt;8 2 1 2 2 2 2 2&lt;BR /&gt;9 3 1 1 1 3 2 1&lt;BR /&gt;10 2 2 2 1 2 2 3&lt;BR /&gt;11 3 99 1 3 3 3 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;conc = cat(lead_1,lead_2,lead_3,lead_4,lead_5,lead_6,lead_7);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc freq data=want;&lt;BR /&gt;tables conc;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Dec 2021 17:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784096#M250145</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-04T17:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784097#M250146</link>
      <description>&lt;P&gt;You start by saying:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;For the variable lead_x, its only possible to have the values: 1, 2, 99 or none present.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you present data where lead_1 = 3, explain this please.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also, if I am understanding your original description properly, the groups you want to create are overlapping, an ID can be in multiple groups. Is that correct?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 17:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784097#M250146</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-04T17:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784102#M250151</link>
      <description>Sorry, to clarify,&lt;BR /&gt;ID are the numbers present in the picture (from 68 to 94). These are persons.&lt;BR /&gt;So person nr 1 in my cohort is record nr 1, and person number 94 has the record id 90.&lt;BR /&gt;&lt;BR /&gt;One person can change groups (the lead numbers). Lead numbers represents operations types. My main goal now is to calculate how many patients were operated with the same type of operation (represented as 1 - 1- 1- 1 or 2- 2- 2- 2) and how many people changed operation type during life time (represented as 1- 1- 2 or 2- 2- 2- 2- 1)&lt;BR /&gt;In total I have actually 4 operations variations - presentes as variable names 1, 2, 3, 99 in lead_types.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So lets say person nr 70 from the original picture I posted. This person only has 1 present in all leads numbers. This person will go in the group called only nr 1.&lt;BR /&gt;Person 79 starts in 2 (lead_1) and changes to 1 (in lead_2).&lt;BR /&gt;&lt;BR /&gt;Person 70 will be continously in group 1. This is one outcome.&lt;BR /&gt;Person 79 will be in the group called 2-1 as this person changes.&lt;BR /&gt;&lt;BR /&gt;As for that, I would like to count:&lt;BR /&gt;how many patient are only operated with type 1 operations during life tim e&lt;BR /&gt;how many only type 2&lt;BR /&gt;how many only type 3&lt;BR /&gt;how many only type 99&lt;BR /&gt;Then for combinations the same as fx,&lt;BR /&gt;how many have the combination of operation type 1 first couple of times and then changes to two and vice verca&lt;BR /&gt;&lt;BR /&gt;Does it make sense now&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Dec 2021 18:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784102#M250151</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-04T18:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784105#M250154</link>
      <description>&lt;P&gt;With a small data set show what you expect for output as well. It is pretty obvious that your "Want" data set in your example code is not what you actually want given that you asking for help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that unless multiple observations are to be combined somehow then providing one of each type of case is what would be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Include missing values since your first example had a lot of missing. For datalines if you enter . it will be read as a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider exactly what you mean by "&lt;SPAN style="font-family: inherit;"&gt;In summary I would like the number of subjects in all possible variations." and provide a more explicit description. Your initial picture showing variable names up to Lead_13 with 4 possible values, missing, 1, 2 and 99 means that there are 67108864 possible permutations (4 to the 13th power). If you have more variables that number of permutations goes up quickly.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;It is easy to test if all of a bunch of variables has the same value excluding missing, the RANGE function returns 0 in that case (all 1, all 2 or all 99, a result of missing means all missing). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Range returns the difference of the smallest to largest value, so a return of 1 means the difference is 1 (which would indicate only 1 and 2 plus any number of missing in your original picture), 98 would mean combinations of at least one 99 and at least one 1 (might include 2), on the same observations, 97 would mean 99 and at least one 2 and no 1.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;MAX, or Min combined with Range tells what value was present for all populated variables. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;The N function returns how many variables have values..&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Some example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data have;
   input s_id lead_1 lead_2 lead_3 lead_4 lead_5 lead_6 lead_7;
   array l (*) lead_:;
   r = range(of l(*));
   m = max(of l(*));
   ones = (m=1 and r=0) ;
   twos = (m=2 and r=0) ;
   all_ones= (ones and n(of l(*))=dim(l));
   all_twos= (ones and n(of l(*))=dim(l));
   num_ones = ones*n(of l(*));
   num_twos = twos*n(of l(*));
   label
      r = 'Range of Lead'
      m = 'Max of Lead'
      ones = 'All populated lead are 1'
      twos = 'All populated lead are 2'
      all_ones = 'All Lead are 1'
      all_twos = 'All Lead are 2'
      num_ones = 'Number Lead with 1 when only 1'
      num_twos = 'Number Lead with 2 when only 2'
   ;
datalines;
1 1 1 1 1 1 1 1
2 1 1 1 . . . .
. 1 1 1 1 1 2 2
4 1 2 2 2 2 2 2
5 1 1 1 1 2 2 2
6 2 2 2 2 2 2 2
7 2 2 2 2 2 1 2
8 2 1 2 2 2 2 2
9 . 1 1 1 . 2 1
10 2 2 2 1 2 2 .
11 . 99 1 . . . 2
;
run;

Proc freq data = have;
   tables ones twos all_ones all_twos num_ones num_twos;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;If you haven't used arrays time to learn. It is one of the basic tools for doing multiple operations with multiple variables. The Dim(arrayname) function returns the number of elements defined for the array.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Note that using the shortcut Lead_:&amp;nbsp; the array uses all variables whose names start with Lead_. If there were 54 lead variables the code would use all of them in the array and none of the code would be need.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;As an aside you can use Group = cat(of L(*)); instead of listing all the variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;If you set Options missing=' '; before running the data step you would not have the . in the group variable if you use CATS instead of CAT function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;The code above uses SAS behavior of returning 1 for a true comparison and 0 for false. So 0 in the Ones variable means not all the values are 1. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 18:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784105#M250154</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-04T18:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784114#M250159</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404450"&gt;@rookie21&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;So lets say person nr 70 from the original picture I posted. This person only has 1 present in all leads numbers. This person will go in the group called only nr 1.&lt;BR /&gt;Person 79 starts in 2 (lead_1) and changes to 1 (in lead_2).&lt;BR /&gt;&lt;BR /&gt;Person 70 will be continously in group 1. This is one outcome.&lt;BR /&gt;Person 79 will be in the group called 2-1 as this person changes.&lt;BR /&gt;&lt;BR /&gt;As for that, I would like to count:&lt;BR /&gt;how many patient are only operated with type 1 operations during life tim e&lt;BR /&gt;how many only type 2&lt;BR /&gt;how many only type 3&lt;BR /&gt;how many only type 99&lt;BR /&gt;Then for combinations the same as fx,&lt;BR /&gt;how many have the combination of operation type 1 first couple of times and then changes to two and vice verca&lt;BR /&gt;&lt;BR /&gt;Does it make sense now&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not completely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please enumerate all possible groups that a person can wind up in.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 19:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784114#M250159</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-04T19:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784129#M250169</link>
      <description>&lt;P&gt;Ok,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im definitely not good to present my challenge. I try again.. Thank u so much for still trying to help me&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Record_id is equal to a person.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lead_x is equal to operation.&amp;nbsp; (lead_1 presenting first operation, lead_2 presenting 2nd operation, lead_3 presenting 3rd operation and so on).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some patients only had 1 operation, and some had multiple.&amp;nbsp;&lt;BR /&gt;In lead_x its possible to have 4 different types of operation presented as nr 1, 2 or 3 and 99 is unknown. So in total 4 different types of operation.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For each patient I would like to know, whether they are in the group:&amp;nbsp;&lt;BR /&gt;- only 1 in all lead_types&amp;nbsp;&lt;/P&gt;&lt;P&gt;- only 2 in all lead_types&lt;/P&gt;&lt;P&gt;- only 3 in all lead_types&lt;/P&gt;&lt;P&gt;- only_99 in all lead_types&lt;/P&gt;&lt;P&gt;for which all 4 above mentioned is that they only hadd same type of operation during life.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, a patient can have been operation with 1 for the first operations and afterwards changed to 2, 3, or 99. This goes for all combinations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So possible groups for each patient consists of:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 --&amp;gt; 1&lt;/P&gt;&lt;P&gt;2--&amp;gt; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 99&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 -&amp;gt; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 -&amp;gt; 3&lt;/P&gt;&lt;P&gt;1--&amp;gt;99&lt;/P&gt;&lt;P&gt;2--&amp;gt; 1&lt;/P&gt;&lt;P&gt;2--&amp;gt;3&lt;/P&gt;&lt;P&gt;2 --&amp;gt;99&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 99&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 2&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say patient 1 has following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;lead_1&amp;nbsp; &amp;nbsp; &amp;nbsp; lead_2&amp;nbsp; &amp;nbsp; &amp;nbsp; lead_3&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Then this patient should be categorized as:&amp;nbsp; "1--&amp;gt;2 group".&amp;nbsp;&lt;/P&gt;&lt;P&gt;So only the change in operation type is of interest for me without how many of each .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes more sense&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 22:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784129#M250169</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-04T22:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784167#M250193</link>
      <description>&lt;P&gt;For sure, Im not being accurate as it is still not, what I would like. But thank u so much for still trying to help me&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try again from the beginning.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Record_id is equal to a person.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lead_x is equal to operation.&amp;nbsp; (lead_1 presenting first operation, lead_2 presenting 2nd operation, lead_3 presenting 3rd operation and so on).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some patients only had 1 operation, and some had multiple.&amp;nbsp;&lt;BR /&gt;In lead_x its possible to have 4 different types of operation presented as nr 1, 2 or 3 and 99 is unknown. So in total 4 different types of operation.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For each patient I would like to know, whether they are in the group:&amp;nbsp;&lt;BR /&gt;- only 1 in all lead_types&amp;nbsp;&lt;/P&gt;&lt;P&gt;- only 2 in all lead_types&lt;/P&gt;&lt;P&gt;- only 3 in all lead_types&lt;/P&gt;&lt;P&gt;- only_99 in all lead_types&lt;/P&gt;&lt;P&gt;for which all 4 above mentioned is that they only hadd same type of operation during life.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, a patient can have been operation with 1 for the first operations and afterwards changed to 2, 3, or 99. This goes for all combinations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So possible groups for each patient consists of:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 --&amp;gt; 1&lt;/P&gt;&lt;P&gt;2--&amp;gt; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 99&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 -&amp;gt; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 -&amp;gt; 3&lt;/P&gt;&lt;P&gt;1--&amp;gt;99&lt;/P&gt;&lt;P&gt;2--&amp;gt; 1&lt;/P&gt;&lt;P&gt;2--&amp;gt;3&lt;/P&gt;&lt;P&gt;2 --&amp;gt;99&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 99&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 2&lt;/P&gt;&lt;P&gt;99 --&amp;gt; 3&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say patient 1 has following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;lead_1&amp;nbsp; &amp;nbsp; &amp;nbsp; lead_2&amp;nbsp; &amp;nbsp; &amp;nbsp; lead_3&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Then this patient should be categorized as:&amp;nbsp; "1--&amp;gt;2 group".&amp;nbsp;&lt;/P&gt;&lt;P&gt;So only the change in operation type is of interest for me without how many of each .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this makes more sense ?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 12:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784167#M250193</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-05T12:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784168#M250194</link>
      <description>&lt;P&gt;So only the first change matters when you do this grouping?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a patient has 1--&amp;gt;2--&amp;gt;3, this patient still is in the 1-&amp;gt;2 group?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length group $ 6;
    array lead lead:;
    if range(of lead:)=0 then group=put(lead_1,6. -l);
    else do i=2 to dim(lead);
        if lead(i)^=lead(i-1) then do;
            group=cats(lead(i-1),'-&amp;gt;',lead(i));
            leave;
        end;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Dec 2021 12:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784168#M250194</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-05T12:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784169#M250195</link>
      <description>&lt;P&gt;No I would actuelly like all changes. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So patient 1 going from 1-3-2-99&amp;nbsp; is one option&amp;nbsp;&lt;/P&gt;
&lt;P&gt;while if patient 2 is having 2-2-2-1 it should be categorized as 2-&amp;gt;1 group.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All "changes" in operation Type I would like to track but not if previous type of operation is the same as the present.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 12:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784169#M250195</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-05T12:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784170#M250196</link>
      <description>&lt;P&gt;Ok THANKS, I have tried this code u wrote:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length group $ 6;
    array lead lead:;
    if range(of lead:)=0 then group=put(lead_1,6. -l);
    else do i=2 to dim(lead);
        if lead(i)^=lead(i-1) then do;
            group=cats(lead(i-1),'-&amp;gt;',lead(i));
            leave;
        end;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It gives me the right output for the variable changes from first type of operation to the second type.&lt;/P&gt;
&lt;P&gt;If I would like to incorporate subsequent changes again, can I do that in same code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So patient have following:&lt;BR /&gt;2&amp;nbsp; -&amp;nbsp; 2&amp;nbsp; &amp;nbsp;-&amp;nbsp; &amp;nbsp;1 -&amp;nbsp; &amp;nbsp;1&amp;nbsp; - 2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I get the output 2 --&amp;gt; 1 --&amp;gt; 2 here?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 12:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784170#M250196</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-05T12:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784192#M250207</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404450"&gt;@rookie21&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So patient have following:&lt;BR /&gt;2&amp;nbsp; -&amp;nbsp; 2&amp;nbsp; &amp;nbsp;-&amp;nbsp; &amp;nbsp;1 -&amp;nbsp; &amp;nbsp;1&amp;nbsp; - 2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I get the output 2 --&amp;gt; 1 --&amp;gt; 2 here?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please state the whole problem, all the requirements, rather than in each message adding additional requirements that were not previously discussed?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 17:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784192#M250207</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-05T17:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784197#M250210</link>
      <description>Yea, sorry. Shall be more specific. &lt;BR /&gt;&lt;BR /&gt;Record-id present patient &lt;BR /&gt;Lead represent operation. Lead_1 first operation, lead_2 second operation, and so on. Possible variable names for all lead_x is: 1, 2, 3 and 99.&lt;BR /&gt;The combination could is what Im looking for. &lt;BR /&gt;One patient might have One or multiple operations. But what I look for:&lt;BR /&gt;Is every change in operation type &lt;BR /&gt;&lt;BR /&gt;Patient 1 with 1 - 2 - 1 in lead_1, lead_2 and lead_3 respectively, I would like the outcome 1-2-1&lt;BR /&gt;&lt;BR /&gt;For patient 2, if it is 1 - 1 - 1 in lead_1, lead_2 and lead_3 respectively, I would like outcome 1 &lt;BR /&gt;&lt;BR /&gt;For patient 3 lets say it is 3 - 99 - 1 with only 3 operation, I would like outcome 3 -&amp;gt; 99 -&amp;gt; 1 &lt;BR /&gt;And so on… &lt;BR /&gt;&lt;BR /&gt;When I have these . i would use proc freq to count number of patients in each combination</description>
      <pubDate>Sun, 05 Dec 2021 18:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784197#M250210</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-05T18:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784199#M250212</link>
      <description>&lt;P&gt;So could there be more than two changes to determine the group?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1-&amp;gt;2-&amp;gt;1-&amp;gt;3-&amp;gt;2&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 18:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784199#M250212</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-05T18:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784205#M250217</link>
      <description>&lt;P&gt;yes, suppose, a patient had five operation with the types being the one u stated:&lt;BR /&gt;&lt;SPAN&gt;1-&amp;gt;2-&amp;gt;1-&amp;gt;3-&amp;gt;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then it should come out as an option 1-&amp;gt;2-&amp;gt;1-&amp;gt;3-&amp;gt;2, as Im interested in all changes&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 20:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784205#M250217</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-05T20:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784217#M250226</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    length group $ 256;
    array lead lead:;
    group=cats(lead(1));
    do i=2 to dim(lead);
        if lead(i)^=lead(i-1) then do;
            group=cats(group,'-&amp;gt;',lead(i));
        end;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Dec 2021 22:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784217#M250226</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-05T22:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Making groups for different outcomes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784502#M250368</link>
      <description>&lt;P&gt;This did help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much !&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 10:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-groups-for-different-outcomes/m-p/784502#M250368</guid>
      <dc:creator>rookie21</dc:creator>
      <dc:date>2021-12-07T10:54:27Z</dc:date>
    </item>
  </channel>
</rss>

