<?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: Looking at observations within a certain group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75886#M16357</link>
    <description>Sort by date and name and then use:&lt;BR /&gt;
&lt;BR /&gt;
if not (first.name and last.name) then output;

Message was edited by: Patrick</description>
    <pubDate>Wed, 21 Apr 2010 04:48:02 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2010-04-21T04:48:02Z</dc:date>
    <item>
      <title>Looking at observations within a certain group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75885#M16356</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
This is probably a pretty simple question, but I can't seem to figure it out.  My dataset looks like the following:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Date         Name            Facility&lt;/B&gt; &lt;BR /&gt;
1/2/09           John               A&lt;BR /&gt;
1/2/09           Gary               B&lt;BR /&gt;
1/2/09           John               B&lt;BR /&gt;
1/4/09           Lisa                C&lt;BR /&gt;
1/4/09           Lisa                C&lt;BR /&gt;
1/5/09           Gary               A&lt;BR /&gt;
1/5/09           Mary               D&lt;BR /&gt;
1/6/09           Jess               B&lt;BR /&gt;
1/6/09           Jess               D&lt;BR /&gt;
1/6/09           Jess               B&lt;BR /&gt;
&lt;BR /&gt;
I want to determine if a person visited a different facility on the same day.  So for this example, John visited facility A and B on 1/2/09, so he would get flagged or outputted to another dataset.  Same thing for Jess on 1/6/09.  &lt;BR /&gt;
&lt;BR /&gt;
How can I code this?  I tried sorting by date and name, then using a lag function.  But that didn't seem to work well if a person had visited multiple facilities on the same day.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help!</description>
      <pubDate>Wed, 21 Apr 2010 03:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75885#M16356</guid>
      <dc:creator>stat11</dc:creator>
      <dc:date>2010-04-21T03:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at observations within a certain group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75886#M16357</link>
      <description>Sort by date and name and then use:&lt;BR /&gt;
&lt;BR /&gt;
if not (first.name and last.name) then output;

Message was edited by: Patrick</description>
      <pubDate>Wed, 21 Apr 2010 04:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75886#M16357</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-04-21T04:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at observations within a certain group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75887#M16358</link>
      <description>Hi ,&lt;BR /&gt;
The below shown code will do the trick...The code has been prepared with the example you have given..&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*use distinct to remove cases like Lisa ie. same day same facility more than once*/&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
select distinct * from test&lt;BR /&gt;
order by date, name, facility;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test2;&lt;BR /&gt;
set test1;&lt;BR /&gt;
format date1 mmddyy10.;&lt;BR /&gt;
date1=lag(date);&lt;BR /&gt;
name1=lag(name);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test3 as&lt;BR /&gt;
select *,&lt;BR /&gt;
(case when (date=date1 and name=name1) then "Y" else "N" end) as Result&lt;BR /&gt;
from test2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table output as&lt;BR /&gt;
select name, result from test3 where result='Y';&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 21 Apr 2010 10:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75887#M16358</guid>
      <dc:creator>syam_india_kochi</dc:creator>
      <dc:date>2010-04-21T10:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at observations within a certain group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75888#M16359</link>
      <description>another possibilty (SAS always has several)&lt;BR /&gt;
&lt;BR /&gt;
data test;                                                                                                                              &lt;BR /&gt;
input Date mmddyy6. Name $ Facility $;                                                                                                  &lt;BR /&gt;
cards;                                                                                                                                  &lt;BR /&gt;
1/2/09 John A                                                                                                                           &lt;BR /&gt;
1/2/09 Gary B                                                                                                                           &lt;BR /&gt;
1/2/09 John B                                                                                                                           &lt;BR /&gt;
1/4/09 Lisa C                                                                                                                           &lt;BR /&gt;
1/4/09 Lisa C                                                                                                                           &lt;BR /&gt;
1/5/09 Gary A                                                                                                                           &lt;BR /&gt;
1/5/09 Mary D                                                                                                                           &lt;BR /&gt;
1/6/09 Jess B                                                                                                                           &lt;BR /&gt;
1/6/09 Jess D                                                                                                                           &lt;BR /&gt;
1/6/09 Jess B                                                                                                                           &lt;BR /&gt;
;                                                                                                                                       &lt;BR /&gt;
run;                                                                                                                                    &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
proc sort data=test;                                                                                                                    &lt;BR /&gt;
  by date name facility;                                                                                                                &lt;BR /&gt;
run;                                                                                                                                    &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
proc transpose data=test out=test2;                                                                                                     &lt;BR /&gt;
  by date name;                                                                                                                         &lt;BR /&gt;
  var facility;                                                                                                                         &lt;BR /&gt;
run;</description>
      <pubDate>Wed, 21 Apr 2010 14:39:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75888#M16359</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2010-04-21T14:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at observations within a certain group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75889#M16360</link>
      <description>...And, just for grins, here's a PROC REPORT approach that creates an output dataset using just one pass through the data and the output dataset has ONLY the dates/names where the number of visits was GE 2 -and- the number of facilities was GE 2. &lt;BR /&gt;
                    &lt;BR /&gt;
WORK.REPOUT is created by PROC REPORT -- which calculates the TOTVISIT column and the FACCNT column on the report -- so those 2 columns are available for WHERE processing. With TOTVISIT and FACCNT used in WHERE processing on the OUT= option, only the report rows that meet the WHERE condition will be written to the output dataset. Also on the OUT= option is the DROP= data set option to drop the automatic variable _BREAK_ and the RENAME= option to rename the absolute column numbers to be the facility values that they represent.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
      &lt;BR /&gt;
[pre]&lt;BR /&gt;
data test; &lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input Date : mmddyy6. Name $ Facility $; &lt;BR /&gt;
return;&lt;BR /&gt;
datalines; &lt;BR /&gt;
1/2/09 John A &lt;BR /&gt;
1/2/09 Gary B &lt;BR /&gt;
1/2/09 John B &lt;BR /&gt;
1/4/09 Lisa C &lt;BR /&gt;
1/4/09 Lisa C &lt;BR /&gt;
1/5/09 Gary A &lt;BR /&gt;
1/5/09 Mary D &lt;BR /&gt;
1/6/09 Jess B &lt;BR /&gt;
1/6/09 Jess D &lt;BR /&gt;
1/6/09 Jess B &lt;BR /&gt;
; &lt;BR /&gt;
run; &lt;BR /&gt;
                &lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='report.html' style=sasweb;&lt;BR /&gt;
              &lt;BR /&gt;
proc report data=test nowd &lt;BR /&gt;
     out=repout(where=(totvisit ge 2 and faccnt ge 2)&lt;BR /&gt;
                rename=(_c3_=A _c4_=B _c5_=C _c6_=D)&lt;BR /&gt;
                drop=_break_);&lt;BR /&gt;
  title 'Report Approach';&lt;BR /&gt;
  column date name facility n=totvisit faccnt;&lt;BR /&gt;
  define date / group f=date9.;&lt;BR /&gt;
  define name /group;&lt;BR /&gt;
  define facility / across;&lt;BR /&gt;
  define totvisit / 'Total Visits';&lt;BR /&gt;
  define faccnt / computed "Facility Count";&lt;BR /&gt;
  ** ACROSS variables have absolute numbers in PROC REPORT;&lt;BR /&gt;
  ** so _c3_ = Facility A, _c4_ = Facility B,;&lt;BR /&gt;
  ** _c5_ = Facility C, _c6_ = Facility D;&lt;BR /&gt;
  compute faccnt;&lt;BR /&gt;
    ** use the N function to get the count of non-missing facility values;&lt;BR /&gt;
    ** when count is 1, means they visited 1 facility, etc.;&lt;BR /&gt;
    ** if there are more than 4 facilities, then logic needs to change;&lt;BR /&gt;
    faccnt=n(_c3_, _c4_, _c5_, _c6_);&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
run;&lt;BR /&gt;
            &lt;BR /&gt;
proc print data=work.repout;&lt;BR /&gt;
  title 'WORK.REPOUT is Output dataset from PROC REPORT';&lt;BR /&gt;
  format date date9.;&lt;BR /&gt;
run;&lt;BR /&gt;
               &lt;BR /&gt;
ods html close;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 21 Apr 2010 18:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-observations-within-a-certain-group/m-p/75889#M16360</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-21T18:33:28Z</dc:date>
    </item>
  </channel>
</rss>

