<?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 Create dataset that tells what visits are excluded for unique ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629783#M186334</link>
    <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I need some help regarding how to check a certain condition for every unique PatientId in my data. In my mock data here we have 4 unique PatientId's. There are 8 possible doctor visits that every patient should do. I want to check, for every unque patient, what visits that are not done.&lt;/P&gt;&lt;PRE class="_3GnarIQX9tD_qsgXkfSDz1"&gt;&lt;CODE class="_34q3PgLsx9zIU5BiSOjFoM"&gt;PatientId VisitNumber
1	  2
1         3	
2	  1
2	  2
2         4
2         5
2         6
2         8
3	  1
3	  2
3	  3
3	  4
3         5
3         6
3         7
3         8
4	  1
4         6
4         8&lt;/CODE&gt;&lt;/PRE&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Optimal output would be:&lt;/P&gt;&lt;PRE class="_3GnarIQX9tD_qsgXkfSDz1"&gt;&lt;CODE class="_34q3PgLsx9zIU5BiSOjFoM"&gt;PatientId     VisitsExcluded
1             1,4,5,6,7,8
2             3,7
3             .            
4             2,3,4,5,7   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;How would you do it? What to write instead of [missing code], or do you have any other go?&lt;/P&gt;&lt;PRE class="_3GnarIQX9tD_qsgXkfSDz1"&gt;&lt;CODE class="_34q3PgLsx9zIU5BiSOjFoM"&gt;* VisitsExcluded (of VisitNumber 1-8);
proc sql;
	create table want as
	select PatientId, case 
		when VisitNumber [missing code]
		else "" end as EventSeq_missing
	from have
	group by PatientId;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Mar 2020 13:13:27 GMT</pubDate>
    <dc:creator>Born_Aioli</dc:creator>
    <dc:date>2020-03-05T13:13:27Z</dc:date>
    <item>
      <title>Create dataset that tells what visits are excluded for unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629783#M186334</link>
      <description>&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;I need some help regarding how to check a certain condition for every unique PatientId in my data. In my mock data here we have 4 unique PatientId's. There are 8 possible doctor visits that every patient should do. I want to check, for every unque patient, what visits that are not done.&lt;/P&gt;&lt;PRE class="_3GnarIQX9tD_qsgXkfSDz1"&gt;&lt;CODE class="_34q3PgLsx9zIU5BiSOjFoM"&gt;PatientId VisitNumber
1	  2
1         3	
2	  1
2	  2
2         4
2         5
2         6
2         8
3	  1
3	  2
3	  3
3	  4
3         5
3         6
3         7
3         8
4	  1
4         6
4         8&lt;/CODE&gt;&lt;/PRE&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;Optimal output would be:&lt;/P&gt;&lt;PRE class="_3GnarIQX9tD_qsgXkfSDz1"&gt;&lt;CODE class="_34q3PgLsx9zIU5BiSOjFoM"&gt;PatientId     VisitsExcluded
1             1,4,5,6,7,8
2             3,7
3             .            
4             2,3,4,5,7   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P class="_1qeIAgB0cPwnLhDF9XSiJM"&gt;How would you do it? What to write instead of [missing code], or do you have any other go?&lt;/P&gt;&lt;PRE class="_3GnarIQX9tD_qsgXkfSDz1"&gt;&lt;CODE class="_34q3PgLsx9zIU5BiSOjFoM"&gt;* VisitsExcluded (of VisitNumber 1-8);
proc sql;
	create table want as
	select PatientId, case 
		when VisitNumber [missing code]
		else "" end as EventSeq_missing
	from have
	group by PatientId;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 13:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629783#M186334</guid>
      <dc:creator>Born_Aioli</dc:creator>
      <dc:date>2020-03-05T13:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset that tells what visits are excluded for unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629788#M186338</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input PatientId VisitNumber;
datalines;
1	  2
1         3	
2	  1
2	  2
2         4
2         5
2         6
2         8
3	  1
3	  2
3	  3
3	  4
3         5
3         6
3         7
3         8
4	  1
4         6
4         8
;

data want;
set have;
by patientid;
length visits $15;
retain req_visits;
if first.patientid then req_visits = '11111111';
substr(req_visits,visitnumber,1) = ' ';
if last.patientid
then do;
  do visitnumber = 1 to 8;
    if substr(req_visits,visitnumber,1) = '1' then visits=catx(',',visits,visitnumber);
  end;
  output;
end;
keep patientid visits;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 13:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629788#M186338</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-05T13:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset that tells what visits are excluded for unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629810#M186352</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input PatientId VisitNumber;
datalines;
1	  2
1         3	
2	  1
2	  2
2         4
2         5
2         6
2         8
3	  1
3	  2
3	  3
3	  4
3         5
3         6
3         7
3         8
4	  1
4         6
4         8
;


data want;
 array v(8) _temporary_ (1:8) ;
 retain k;
 if _n_=1 then  k=peekclong(addrlong(v(1)),64);
 do until(last.PatientId);
  set have;
  by PatientId;
  _n_=whichn(visitnumber,of v(*));
  if _n_ then call missing(v(_n_));
 end;
 VisitsExcluded=compbl(compress(strip(catx(' ',of v(*))),'.'));
 call pokelong(k,addrlong(v(1)),64);
 drop k visitnumber;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 14:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629810#M186352</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-05T14:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create dataset that tells what visits are excluded for unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629827#M186363</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input PatientId VisitNumber;&lt;BR /&gt;datalines;&lt;BR /&gt;1 2&lt;BR /&gt;1 3 &lt;BR /&gt;2 1&lt;BR /&gt;2 2&lt;BR /&gt;2 4&lt;BR /&gt;2 5&lt;BR /&gt;2 6&lt;BR /&gt;2 8&lt;BR /&gt;3 1&lt;BR /&gt;3 2&lt;BR /&gt;3 3&lt;BR /&gt;3 4&lt;BR /&gt;3 5&lt;BR /&gt;3 6&lt;BR /&gt;3 7&lt;BR /&gt;3 8&lt;BR /&gt;4 1&lt;BR /&gt;4 6&lt;BR /&gt;4 8&lt;BR /&gt;;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table id as&lt;BR /&gt;select distinct PatientID from have;&lt;/P&gt;
&lt;P&gt;create table temp as&lt;BR /&gt;select *&lt;BR /&gt;from (select * from id,(select distinct VisitNumber from have)) &lt;BR /&gt;except&lt;BR /&gt;select * from have;&lt;/P&gt;
&lt;P&gt;create table want as&lt;BR /&gt;select a.*,b.VisitNumber&lt;BR /&gt;from id as a left join temp as b on a.PatientID=b.PatientID;&lt;BR /&gt;quit;&lt;BR /&gt;data final_want;&lt;BR /&gt;do until(last.PatientID);&lt;BR /&gt;set want;&lt;BR /&gt;by PatientID;&lt;BR /&gt;length VisitsExcluded $ 80;&lt;BR /&gt;VisitsExcluded=catx(',',VisitsExcluded,VisitNumber);&lt;BR /&gt;end;&lt;BR /&gt;drop VisitNumber;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 14:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-dataset-that-tells-what-visits-are-excluded-for-unique-ID/m-p/629827#M186363</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-05T14:48:09Z</dc:date>
    </item>
  </channel>
</rss>

