<?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: Comparing vertical data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599630#M16537</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id
year
modal $
;
cards;
111   2006    1               
111   2006    2               
111   2006    123               
112   2006    13               
112   2006    12               
113   2006    12               
113   2006    2               
113   2006    2               
;
data temp;
 set have;
 do i=1 to length(modal);
  temp=char(modal,i);output;
 end;
 drop i modal;
run;
proc sort data=temp nodupkey;
by id year temp;
run;
data want;
 do until(last.year);
   set temp;
   by id year;
   length want $ 80;
   want=cats(want,temp);
 end;
 drop temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 27 Oct 2019 11:58:09 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-10-27T11:58:09Z</dc:date>
    <item>
      <title>Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599617#M16532</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a problem with the a dataset like the following table.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;year&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;modal&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;111&lt;/P&gt;&lt;P&gt;111&lt;/P&gt;&lt;P&gt;111&lt;/P&gt;&lt;P&gt;112&lt;/P&gt;&l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gt;2009&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;123&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to find out which modal exists for each id and year.&lt;/P&gt;&lt;P&gt;The following combinations are possible: 1; 2; 3; 12; 13; 23 and 123.&lt;/P&gt;&lt;P&gt;What the output should look like:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;year&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Modal_total&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;111&lt;/P&gt;&lt;P&gt;112&lt;/P&gt;&lt;P&gt;113&lt;/P&gt;&lt;P&gt;112&lt;/P&gt;&lt;P&gt;113&lt;/P&gt;&lt;P&gt;114&lt;/P&gt;&lt;P&gt;115&lt;/P&gt;&lt;P&gt;114&lt;/P&gt;&lt;P&gt;115&lt;/P&gt;&lt;P&gt;116&lt;/P&gt;&lt;P&gt;114&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2006&lt;/P&gt;&lt;P&gt;2006&lt;/P&gt;&lt;P&gt;2006&lt;/P&gt;&lt;P&gt;2007&lt;/P&gt;&lt;P&gt;2007&lt;/P&gt;&lt;P&gt;2007&lt;/P&gt;&lt;P&gt;2007&lt;/P&gt;&lt;P&gt;2008&lt;/P&gt;&lt;P&gt;2008&lt;/P&gt;&lt;P&gt;2008&lt;/P&gt;&lt;P&gt;2009&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;123&lt;/P&gt;&lt;P&gt;123&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;123&lt;/P&gt;&lt;P&gt;23&lt;/P&gt;&lt;P&gt;13&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;13&lt;/P&gt;&lt;P&gt;23&lt;/P&gt;&lt;P&gt;123&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks a lot in advance. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 09:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599617#M16532</guid>
      <dc:creator>annaxenia1</dc:creator>
      <dc:date>2019-10-27T09:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599620#M16533</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296999"&gt;@annaxenia1&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you be more specific about the logic here? How exactly is&amp;nbsp;&lt;SPAN&gt;Modal_total calculated?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 10:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599620#M16533</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-27T10:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599621#M16534</link>
      <description>Hi draycut and thanks for the quik reply:)&lt;BR /&gt;&lt;BR /&gt;If you look at id 116 in 2008, the modal 2 occurs three times and the modal 3 occurs once. If a modal occurs one or more times doesn`t matter. For me it is interesting which numbers occur at all. In this case the modal_total should be 23 because 2 and 3 occurs.</description>
      <pubDate>Sun, 27 Oct 2019 10:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599621#M16534</guid>
      <dc:creator>annaxenia1</dc:creator>
      <dc:date>2019-10-27T10:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599627#M16535</link>
      <description>&lt;P&gt;Is the variable modal stored as character or numeric?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 11:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599627#M16535</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-27T11:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599629#M16536</link>
      <description>as numeric</description>
      <pubDate>Sun, 27 Oct 2019 11:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599629#M16536</guid>
      <dc:creator>annaxenia1</dc:creator>
      <dc:date>2019-10-27T11:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599630#M16537</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id
year
modal $
;
cards;
111   2006    1               
111   2006    2               
111   2006    123               
112   2006    13               
112   2006    12               
113   2006    12               
113   2006    2               
113   2006    2               
;
data temp;
 set have;
 do i=1 to length(modal);
  temp=char(modal,i);output;
 end;
 drop i modal;
run;
proc sort data=temp nodupkey;
by id year temp;
run;
data want;
 do until(last.year);
   set temp;
   by id year;
   length want $ 80;
   want=cats(want,temp);
 end;
 drop temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Oct 2019 11:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599630#M16537</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-10-27T11:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599634#M16538</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296999"&gt;@annaxenia1&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another approach, assuming that your input dataset ("HAVE") is sorted by &lt;FONT face="courier new,courier"&gt;year id&lt;/FONT&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_: modal);
length _c $3;
do until(last.id);
  set have;
  by year id;
  if modal in (1,12,13,123) then substr(_c,1,1)='1';
  if modal in (2,12,23,123) then substr(_c,2,1)='2';
  if modal in (3,13,23,123) then substr(_c,3,1)='3';
end;
Modal_total=compress(_c);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This creates &lt;FONT face="courier new,courier"&gt;Modal_total&lt;/FONT&gt; as a character variable (of length 3). If you prefer a numeric variable, please replace the assignment statement by&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Modal_total=input(compress(_c),3.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For input datasets with more than three different values (1, 2, 3) the lists in the IF conditions might become unwieldy. In this case I'd rather convert the &lt;FONT face="courier new,courier"&gt;modal&lt;/FONT&gt; values to character and apply a suitable character function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Example of a variant using a character function (FINDC), also using an array instead of a character variable _c:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_: modal);
array _c[3] $1;
do until(last.id);
  set have;
  by year id;
  _m=put(modal,3.);
  do _i='1', '2', '3';
    if findc(_m,_i) then _c[input(_i,1.)]=_i;
  end;
end;
length Modal_total $3;
Modal_total=cats(of _c[*]);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Oct 2019 13:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599634#M16538</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-27T13:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing vertical data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599640#M16539</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296999"&gt;@annaxenia1&lt;/a&gt;&amp;nbsp; My share of fun. I must admit, I kinda copied the idea from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;. Sorry Xia!&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id year modal ;
cards;
111	2006	1
111	2006	2
111	2006	123
112	2006	13
112	2006	12
113	2006	12
113	2006	2
113	2006	2
112	2007	2
112	2007	2
112	2007	123
112	2007	23
112	2007	23
113	2007	23
113	2007	3
113	2007	3
114	2007	3
114	2007	1
115	2007	1
115	2007	1
114	2008	12
114	2008	1
115	2008	13
115	2008	1
116	2008	2
116	2008	2
116	2008	2
116	2008	3
114	2009	3
114	2009	123
114	2009	1
114	2009	2
;

proc sort data=have out=_have;
by id year;
run;

data want;
 do until(last.year);
  set _have;
  by id year;
  array t(99999)$ _temporary_ ;
  do _n_=1 to length(cats(modal));
   temp=char(cats(modal),_n_);
   if temp not in t then t(temp)=temp;
  end;
 end;
 Modal_total=cats(of t(*));
 call missing(of t(*));
 drop temp modal;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 13:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Comparing-vertical-data/m-p/599640#M16539</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-27T13:44:36Z</dc:date>
    </item>
  </channel>
</rss>

