<?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: How to flag observations with multiple rows v.s. sing row? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/691161#M210323</link>
    <description>&lt;P&gt;And here the whole thing, along with creating the sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=" " dsd;
input class $ class_code $ teacher $;
datalines;
1 M5002 A
2 M5032 B
3 M5082 A
  C
  D
4 M5082 B
  C
  D
;

data have_expanded;
set have;
retain _class _class_code;
if class ne .
then _class = class;
else class = _class;
if class_code ne ""
then _class_code = class_code;
else class_code = _class_code;
drop _:;
run;

proc sql;
create table want as
  select
    class,
    class_code,
    teacher,
    count(*) as n_teacher,
    (calculated n_teacher &amp;gt; 1) as coteach
  from have_expanded
  group by class, class_code
;
quit;

proc print data=have noobs;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                       class_
              class     code     teacher

                1      M5002        A   
                2      M5032        B   
                3      M5082        A   
                                    C   
                                    D   
                4      M5082        B   
                                    C   
                                    D   
                                                      

           class_
  class     code     teacher    n_teacher    coteach

    1      M5002        A           1           0   
    2      M5032        B           1           0   
    3      M5082        A           3           1   
    3      M5082        D           3           1   
    3      M5082        C           3           1   
    4      M5082        C           3           1   
    4      M5082        B           3           1   
    4      M5082        D           3           1   
&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Oct 2020 08:05:12 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-10-13T08:05:12Z</dc:date>
    <item>
      <title>How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690638#M210101</link>
      <description>&lt;P&gt;I have a data as follows:&lt;/P&gt;&lt;P&gt;Class 1 and 2 have single row, that means these two class taught independently by A and B respectively.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Class 3 and 3 have multiple&amp;nbsp; rows, that means these two class co-taught independently by several teachers. for example, class 3 was&amp;nbsp;&amp;nbsp;co-taught by teachers A, C, and D.&amp;nbsp;&lt;/P&gt;&lt;P&gt;class 4 was&amp;nbsp;&amp;nbsp;co-taught by teachers B, C, and D.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tinghlin_0-1602302348660.png" style="width: 364px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50516i0AD9EAF471252CA1/image-dimensions/364x275?v=v2" width="364" height="275" role="button" title="tinghlin_0-1602302348660.png" alt="tinghlin_0-1602302348660.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to creat two variables "coteach" "N_teacher" and&amp;nbsp; make the data as follows:&lt;/P&gt;&lt;P&gt;the variable "coteach" is an indicator variable,&amp;nbsp; and "N_teacher" counts number of teahcers teach the class&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tinghlin_0-1602302933148.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50517i99DFD3669BFA1E91/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tinghlin_0-1602302933148.png" alt="tinghlin_0-1602302933148.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 04:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690638#M210101</guid>
      <dc:creator>tinghlin</dc:creator>
      <dc:date>2020-10-10T04:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690643#M210105</link>
      <description>&lt;P&gt;Please supply your SAS data in data steps with datalines, so we know with what the code has to work.&lt;/P&gt;
&lt;P&gt;Pictures(!) of spreadsheets tell us next to nothing about your SAS datasets, and can't be used for testing.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 06:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690643#M210105</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-10T06:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690644#M210106</link>
      <description>&lt;P&gt;PS I have shown you in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/counting-number-of-observations/m-p/687473/highlight/true#M208702" target="_blank" rel="noopener"&gt;this post&lt;/A&gt;&amp;nbsp;how such a data step looks.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 06:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690644#M210106</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-10T06:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690652#M210109</link>
      <description>&lt;P&gt;IT IS AN EXCEL FILE.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 08:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690652#M210109</guid>
      <dc:creator>tinghlin</dc:creator>
      <dc:date>2020-10-10T08:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690657#M210111</link>
      <description>&lt;P&gt;Then you should ask your question in an Excel forum &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seriously, it is very hard to give advice if one cannot see the data as it is present in SAS. Especially with such a layout, where some texts may or may not be repeated over several observations.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 10:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690657#M210111</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-10T10:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690658#M210112</link>
      <description>&lt;P&gt;what if i import the excel into SAS and proc print the data as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Obs class class_code teacher12345678 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;M5002&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;M5032&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;M5082&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;M5082&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sat, 10 Oct 2020 10:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690658#M210112</guid>
      <dc:creator>tinghlin</dc:creator>
      <dc:date>2020-10-10T10:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690661#M210113</link>
      <description>&lt;P&gt;The first step needed is to expand the part-missing columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_expanded;
set have;
retain _class _class_code;
if class ne .
then _class = class;
else class = _class;
if class_code ne ""
then _class_code = class_code;
else class_code = _class_code;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, this SQL should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    class,
    class_code,
    teacher,
    count(*) as n_teacher,
    (calculated n_teacher &amp;gt; 1) as coteach
  from have_expanded
  group by class, class_code
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 11:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/690661#M210113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-10T11:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to flag observations with multiple rows v.s. sing row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/691161#M210323</link>
      <description>&lt;P&gt;And here the whole thing, along with creating the sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=" " dsd;
input class $ class_code $ teacher $;
datalines;
1 M5002 A
2 M5032 B
3 M5082 A
  C
  D
4 M5082 B
  C
  D
;

data have_expanded;
set have;
retain _class _class_code;
if class ne .
then _class = class;
else class = _class;
if class_code ne ""
then _class_code = class_code;
else class_code = _class_code;
drop _:;
run;

proc sql;
create table want as
  select
    class,
    class_code,
    teacher,
    count(*) as n_teacher,
    (calculated n_teacher &amp;gt; 1) as coteach
  from have_expanded
  group by class, class_code
;
quit;

proc print data=have noobs;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                       class_
              class     code     teacher

                1      M5002        A   
                2      M5032        B   
                3      M5082        A   
                                    C   
                                    D   
                4      M5082        B   
                                    C   
                                    D   
                                                      

           class_
  class     code     teacher    n_teacher    coteach

    1      M5002        A           1           0   
    2      M5032        B           1           0   
    3      M5082        A           3           1   
    3      M5082        D           3           1   
    3      M5082        C           3           1   
    4      M5082        C           3           1   
    4      M5082        B           3           1   
    4      M5082        D           3           1   
&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Oct 2020 08:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-flag-observations-with-multiple-rows-v-s-sing-row/m-p/691161#M210323</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-13T08:05:12Z</dc:date>
    </item>
  </channel>
</rss>

