<?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: Flagging if condition if ever met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890074#M351684</link>
    <description>&lt;P&gt;As long as your data are already sorted by ID, it doesn't matter where the code "A" occurs.&amp;nbsp; You can always do a MERGE of the code="A" obs with all the obs.&amp;nbsp; No further sorting is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code below is edited, and tested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = "," dsd missover;
input ID $  VID  Code $ CodeA;
datalines;
1,5,A,1
1,5,B, 
2,6,A,1
2,6,B,
2,3,C,
3,4,B,
3,4,C,
run;
data want;
  merge have  (where=(code='A') in=found_a_qualifier)
        have (in=allobs);
  by id;
  retain vid_codea;
  if first.id then vid_codea=found_a_qualifier; /*Changed first.have to first.id */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Aug 2023 13:02:34 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-08-20T13:02:34Z</dc:date>
    <item>
      <title>Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890070#M351681</link>
      <description>&lt;P&gt;I have been trying for hours so I decided to reach out for help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is an example of my data. I created a flag if the Code is A by using if then do. However, I also need to flag all rows of the same VID if the code was ever A. I have tried using a data step but I cannot seem to figure out anything that works. Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Example Have:&lt;BR /&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ID&lt;SPAN class=""&gt;&amp;nbsp; VID&amp;nbsp; Code&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;CodeA&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=""&gt;&amp;nbsp; B&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 6 &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; B&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 2 &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Example Want:&lt;BR /&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ID&lt;SPAN class=""&gt;&amp;nbsp; VID&amp;nbsp; Code&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;CodeA&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=""&gt;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 6 &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 2 &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;or&lt;U&gt; Example want:&lt;/U&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ID&lt;SPAN class=""&gt;&amp;nbsp; VID&amp;nbsp; Code&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;CodeA&amp;nbsp; VID_CODEA&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 1&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=""&gt;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 6 &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 2 &lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 20:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890070#M351681</guid>
      <dc:creator>stats_auca</dc:creator>
      <dc:date>2023-08-19T20:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890072#M351682</link>
      <description>&lt;P&gt;This one is always a bit tricky. If you ever need to find this again, you would call it last observation carried forward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = "," dsd missover;
input ID $  VID  Code $ CodeA;
datalines;
1,5,A,1
1,5,B, 
2,6,A,1
2,6,B,
2,3,C,
3,4,B,
3,4,C,
;
run;

proc sort data = have;
	by id vid code;
run;

data want;
set have;
length vid_codea 3.;
retain vid_codea;
by id vid;
	if code = 'A' then codeA = 1;
	if first.vid then call missing(vid_codeA);
	if not missing(codeA) then vid_codeA = codeA;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;ID	VID	Code	CodeA	vid_codea
1	5	A	1	1
1	5	B	.	1
2	3	C	.	.
2	6	A	1	1
2	6	B	.	1
3	4	B	.	.
3	4	C	.	.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2023 22:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890072#M351682</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2023-08-19T22:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890074#M351684</link>
      <description>&lt;P&gt;As long as your data are already sorted by ID, it doesn't matter where the code "A" occurs.&amp;nbsp; You can always do a MERGE of the code="A" obs with all the obs.&amp;nbsp; No further sorting is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code below is edited, and tested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter = "," dsd missover;
input ID $  VID  Code $ CodeA;
datalines;
1,5,A,1
1,5,B, 
2,6,A,1
2,6,B,
2,3,C,
3,4,B,
3,4,C,
run;
data want;
  merge have  (where=(code='A') in=found_a_qualifier)
        have (in=allobs);
  by id;
  retain vid_codea;
  if first.id then vid_codea=found_a_qualifier; /*Changed first.have to first.id */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 13:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890074#M351684</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-20T13:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890078#M351687</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp;Thank you so much. To be clear, column vid_codea is what I am looking for, correct? If so, it seemed to work perfectly!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 00:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890078#M351687</guid>
      <dc:creator>stats_auca</dc:creator>
      <dc:date>2023-08-20T00:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890083#M351688</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt; I spoke too soon. Below is the dataset and there should be a '1' for the bolded lines with the same VID when Code=1.&amp;nbsp; Any ideas what may be the issue?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID	VID	 Code	CodeA	vid_codea
1	5	  A	      1	       1
&lt;STRONG&gt;1	5	  B	      .	       .&lt;/STRONG&gt;
2	3	  C	      .        .
2	6	  A	      1        1
&lt;STRONG&gt;2	6	  B		  .        .&lt;/STRONG&gt;
3	4	  B		  .        .
3	4	  C		  .        .&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Aug 2023 03:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890083#M351688</guid>
      <dc:creator>stats_auca</dc:creator>
      <dc:date>2023-08-20T03:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890084#M351689</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;thank you! for some reason when I run the code, both the vid_codea and found_a_qualifier are empty columns? &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 03:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890084#M351689</guid>
      <dc:creator>stats_auca</dc:creator>
      <dc:date>2023-08-20T03:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890089#M351691</link>
      <description>You can subset your first data:&lt;BR /&gt;Data Data_A;&lt;BR /&gt;Set Data_Have;&lt;BR /&gt;Where code = “A”;&lt;BR /&gt;Run;&lt;BR /&gt;Example: Data_A&lt;BR /&gt;ID VID Code CodeA&lt;BR /&gt;1 5 A 1&lt;BR /&gt;2 6 A 1&lt;BR /&gt;&lt;BR /&gt;After that use proc sql to assign a new flag as you want:&lt;BR /&gt;Proc sql noprint;&lt;BR /&gt;Create table Data_A_want as&lt;BR /&gt;Select *, case when VID in (select distinct VID from Data_A) then 1 end else 0 as VID_ CODEA&lt;BR /&gt;From Data_Have;&lt;BR /&gt;Quit;&lt;BR /&gt;&lt;BR /&gt;The above code should give you the flag you want.</description>
      <pubDate>Sun, 20 Aug 2023 04:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890089#M351691</guid>
      <dc:creator>vidhipatel01</dc:creator>
      <dc:date>2023-08-20T04:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890094#M351695</link>
      <description>&lt;P&gt;Double DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.vid);
  set have;
  by id vid notsorted;
  if code = "A" then codea = 1;
end;
do until (last.vid);
  set have;
  by id vid notsorted;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Aug 2023 07:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890094#M351695</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-20T07:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890099#M351698</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/445888"&gt;@stats_auca&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;thank you! for some reason when I run the code, both the vid_codea and found_a_qualifier are empty columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; I have corrected the code to use&amp;nbsp; &amp;nbsp; &amp;nbsp;first.id&amp;nbsp; instead of first.have.&amp;nbsp; This is the result of my failure to test the code against your sample data.&amp;nbsp; I've edited the response, with tested code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 13:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890099#M351698</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-20T13:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890105#M351704</link>
      <description>&lt;P&gt;To test if a Boolean is ever TRUE just take the MAX().&amp;nbsp; This will work with your 1/. coded variable just as well as with a normal 1/0 coded Boolean variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID $  VID  Code $ CodeA;
datalines;
1 5 A 1
1 5 B . 
2 6 A 1
2 6 B .
2 3 C .
3 4 B .
3 4 C .
;

proc sql ;
create table want as
  select *
       , max(codeA) as any_codeA
  from have
  group by id
;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                            Code     any_
Obs    ID    VID    Code      A     codeA

 1     1      5      A        1       1
 2     1      5      B        .       1
 3     2      6      A        1       1
 4     2      3      C        .       1
 5     2      6      B        .       1
 6     3      4      C        .       .
 7     3      4      B        .       .
&lt;/PRE&gt;
&lt;P&gt;But to do other aggregations like are ALL of the observations TRUE you need to have real Boolean flags where the FALSE results are coded as zero instead of missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID $  VID  Code $ ;
datalines;
1 5 A
1 5 B
2 6 A
2 6 B
2 3 C
3 4 B
3 4 C
4 7 A
4 7 A
;

proc sql ;
create table want as
  select *
       , (code='A') as codeA
       , max(calculated codeA) as any_codeA
       , min(calculated codeA) as all_codeA
  from have
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                            code     any_     all_
Obs    ID    VID    Code      A     codeA    codeA

 1     1      5      B        0       1        0
 2     1      5      A        1       1        0
 3     2      6      A        1       1        0
 4     2      3      C        0       1        0
 5     2      6      B        0       1        0
 6     3      4      C        0       0        0
 7     3      4      B        0       0        0
 8     4      7      A        1       1        1
 9     4      7      A        1       1        1
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 14:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890105#M351704</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-20T14:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890116#M351712</link>
      <description>&lt;P&gt;If I may drop in?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; input ID $  VID  Code $ ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there really a sense for the "$" after ID?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 19:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890116#M351712</guid>
      <dc:creator>SaSoDude</dc:creator>
      <dc:date>2023-08-20T19:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890122#M351716</link>
      <description>&lt;P&gt;The $ means read it as character.&amp;nbsp; Since I was lazy and did not DEFINE the variables before they appeared in the INPUT statement I need to have that or else it will make ID as a NUMERIC variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should not store identifiers as numbers as there is no reason to do arithmetic with them.&amp;nbsp; What would the MEAN value of ID mean?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 21:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890122#M351716</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-20T21:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890130#M351719</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You should not store identifiers as numbers as there is no reason to do arithmetic with them.&amp;nbsp; What would the MEAN value of ID mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agree.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there may be value in knowing the MINIMUM and MAXIMUM ID values (or maybe the range), if ID's were historically assigned in numeric sequence.&amp;nbsp; That's not enough in my mind to justify numeric ID's, when character vars could also be sequenced.&amp;nbsp; But I suspect a lot of ID systems have started out with such numeric sequences.&amp;nbsp; I've certainly seen a lot of surveys do exactly that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2023 22:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890130#M351719</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-20T22:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890424#M351840</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; -&amp;nbsp;I can follow your explanation, but still have a different view on declaring IDs.&lt;/P&gt;&lt;P&gt;In this case the values of this ID take only numeric values and for this reason alone I see no advantage to declare the ID as a character.&lt;/P&gt;&lt;P&gt;I also know from other BI tools that especially with IDs numbers can be processed much faster than characters. Whether this is also the case in SAS, I do not know - I am still too new.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 15:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890424#M351840</guid>
      <dc:creator>SaSoDude</dc:creator>
      <dc:date>2023-08-22T15:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890430#M351843</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/447370"&gt;@SaSoDude&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; -&amp;nbsp;I can follow your explanation, but still have a different view on declaring IDs.&lt;/P&gt;
&lt;P&gt;In this case the values of this ID take only numeric values and for this reason alone I see no advantage to declare the ID as a character.&lt;/P&gt;
&lt;P&gt;I also know from other BI tools that especially with IDs numbers can be processed much faster than characters. Whether this is also the case in SAS, I do not know - I am still too new.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As long as you understand the risks it is fine.&amp;nbsp; Why other databases work in a way that numeric identifiers work "faster" is something for them to address.&amp;nbsp; Perhaps it is because they allow variable length strings?&amp;nbsp; Other database also allow DECIMAL and INTEGER data types that allow for more possible unique identifiers and more compact storage than floating point numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 16:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890430#M351843</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-22T16:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging if condition if ever met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890458#M351862</link>
      <description>This code seemed to do the trick. Thank you so much!</description>
      <pubDate>Tue, 22 Aug 2023 18:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-if-condition-if-ever-met/m-p/890458#M351862</guid>
      <dc:creator>stats_auca</dc:creator>
      <dc:date>2023-08-22T18:50:15Z</dc:date>
    </item>
  </channel>
</rss>

