<?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 Conditional flag by groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691524#M210488</link>
    <description>&lt;P&gt;Dear Everyone,&lt;/P&gt;
&lt;P&gt;May I please ask how do we get the last column, 'flag' given my input data containing id, date, vis and site?&lt;BR /&gt;I would like to be able to flag the most recent non-missing var from a visit given the date by site for patients.&lt;/P&gt;
&lt;P&gt;Your help is very much appreciated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id	date	vis	site	var	flag
1	01-Jan-2020	1	1		1
1	02-Feb-2020	2	1	10	1
1	03-Mar-2020	3	1	11	0
1	10-Mar-2020	3	1	12	1
1	05-Apr-2020	4	1	11	1
1	06-May-2020	5	1	9	1
1	07-Jun-2020	6	1	.	0
1	06-Jun-2020	6	1	13	1
1	09-Aug-2020	8	1	10	1
1	01-Jan-2020	1	2	9	1
1	02-Feb-2020	2	2	7	1
1	03-Mar-2020	3	2	5	1
1	10-Mar-2020	3	2	7	1
1	05-Apr-2020	4	2	8	1
1	06-May-2020	5	2	.	1
1	07-Jun-2020	6	2	7	1
1	25-Aug-2020	8	2	.	0
1	09-Aug-2020	8	2	10	1
2	01-Jan-2020	1	1	4	1
2	02-Feb-2020	2	1	10	1
2	03-Mar-2020	3	1	11	0
2	10-Mar-2020	3	1	12	1
2	05-Apr-2020	4	1	11	1
2	06-May-2020	5	1	9	1
2	07-Jun-2020	6	1	9	1
2	25-Jun-2020	7	1	13	1
2	09-Aug-2020	8	1	10	1
2	01-Jan-2020	1	2	9	1
2	02-Feb-2020	2	2	7	1
2	03-Mar-2020	3	2	5	0
2	10-Mar-2020	3	2	7	1
2	05-Apr-2020	4	2	8	1
2	06-May-2020	5	2	6	1
2	07-Jun-2020	6	2	7	1
2	31-Aug-2020	8	2	20	1
2	09-Aug-2020	8	2	10	0
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2020 14:09:36 GMT</pubDate>
    <dc:creator>Miracle</dc:creator>
    <dc:date>2020-10-14T14:09:36Z</dc:date>
    <item>
      <title>Conditional flag by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691524#M210488</link>
      <description>&lt;P&gt;Dear Everyone,&lt;/P&gt;
&lt;P&gt;May I please ask how do we get the last column, 'flag' given my input data containing id, date, vis and site?&lt;BR /&gt;I would like to be able to flag the most recent non-missing var from a visit given the date by site for patients.&lt;/P&gt;
&lt;P&gt;Your help is very much appreciated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id	date	vis	site	var	flag
1	01-Jan-2020	1	1		1
1	02-Feb-2020	2	1	10	1
1	03-Mar-2020	3	1	11	0
1	10-Mar-2020	3	1	12	1
1	05-Apr-2020	4	1	11	1
1	06-May-2020	5	1	9	1
1	07-Jun-2020	6	1	.	0
1	06-Jun-2020	6	1	13	1
1	09-Aug-2020	8	1	10	1
1	01-Jan-2020	1	2	9	1
1	02-Feb-2020	2	2	7	1
1	03-Mar-2020	3	2	5	1
1	10-Mar-2020	3	2	7	1
1	05-Apr-2020	4	2	8	1
1	06-May-2020	5	2	.	1
1	07-Jun-2020	6	2	7	1
1	25-Aug-2020	8	2	.	0
1	09-Aug-2020	8	2	10	1
2	01-Jan-2020	1	1	4	1
2	02-Feb-2020	2	1	10	1
2	03-Mar-2020	3	1	11	0
2	10-Mar-2020	3	1	12	1
2	05-Apr-2020	4	1	11	1
2	06-May-2020	5	1	9	1
2	07-Jun-2020	6	1	9	1
2	25-Jun-2020	7	1	13	1
2	09-Aug-2020	8	1	10	1
2	01-Jan-2020	1	2	9	1
2	02-Feb-2020	2	2	7	1
2	03-Mar-2020	3	2	5	0
2	10-Mar-2020	3	2	7	1
2	05-Apr-2020	4	2	8	1
2	06-May-2020	5	2	6	1
2	07-Jun-2020	6	2	7	1
2	31-Aug-2020	8	2	20	1
2	09-Aug-2020	8	2	10	0
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 14:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691524#M210488</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-10-14T14:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional flag by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691539#M210492</link>
      <description>&lt;P&gt;With id = 1, site = 1, and vis = 3, you flag both observations as 1, but with id = 2, site = 2, vis = 8, you only flag the later as 1; what is the difference here?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 14:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691539#M210492</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-14T14:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional flag by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691540#M210493</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;for pointing out.&lt;BR /&gt;Post is now corrected.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 14:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691540#M210493</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-10-14T14:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional flag by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691544#M210494</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id site vis date;
run;

data want;
set have;
by id site vis;
flag = last.vis;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Oct 2020 14:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691544#M210494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-14T14:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional flag by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691571#M210509</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; for trying to help&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I managed to get it done correctly by following this post here instead&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/create-a-flag-for-first-non-zero-observation-by-group/td-p/263731" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/create-a-flag-for-first-non-zero-observation-by-group/td-p/263731&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 15:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-flag-by-groups/m-p/691571#M210509</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-10-14T15:43:37Z</dc:date>
    </item>
  </channel>
</rss>

