<?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: Need to make a flag for id which has first flag as Y in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587220#M167698</link>
    <description>&lt;P&gt;Here is a non hash approach that does not depend on the ecs variable, but requires that your data is sorted by ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    do until (last.ID);
        set ads;
        by ID;
        if first.ID then _iorc_=ifn(flag1='Y', 1, 0);
        if first.ID ne 1 &amp;amp; _iorc_=1 &amp;amp; flag1='Y' then flag2='Y';
        else                                         flag2='N';
    end;
    do until (last.ID);
        set ads;
        by ID;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID  ecs par   flag1  flag2
12  1   par1  Y      Y
12  2   par1  Y      Y
12  3   par1  Y      Y
12  4   par2  Y      Y
13  1   par1         N
13  2   par1  Y      N
13  3   par1  N      N
13  4   par2  Y      N
14  1   par1  N      N&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Sep 2019 07:03:41 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-09-10T07:03:41Z</dc:date>
    <item>
      <title>Need to make a flag for id which has first flag as Y</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587185#M167685</link>
      <description>&lt;P&gt;I need to create a new flag with subjects which has first id as "Y" and atleast 1 flag later for same id as "Y"&lt;/P&gt;&lt;P&gt;In the below example i want to see if ecs=1 has flag1="Y" then create flag2="Y" for that id&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;data WORK.ADS;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;infile datalines dsd truncover;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;input ID:BEST12. ecs:BEST12. par:$8. flag1:$1.;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;datalines4;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;12,1,par1,Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;12,2,par1,Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;12,3,par1,Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;12,4,par2,Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;13,1,par1,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;13,2,par1,Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;13,3,par1,N&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;13,4,par2,Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;14,1,par1,N&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;;;;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;the output i need to get is falg2="Y" for id 12,14 and flag2="N" for 13&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;any help&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 10:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587185#M167685</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2019-09-09T10:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need to make a flag for id which has first flag as Y</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587186#M167686</link>
      <description>&lt;P&gt;Why would flag2="Y" for ID=14? It does not have Flag1="Y" for the first obs in the ID? Or later for that matter&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 10:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587186#M167686</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-09T10:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need to make a flag for id which has first flag as Y</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587214#M167695</link>
      <description>&lt;P&gt;orry, it should not be Y. my mistake&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 12:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587214#M167695</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2019-09-09T12:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need to make a flag for id which has first flag as Y</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587217#M167696</link>
      <description>&lt;P&gt;No problem. Given you have your ecs variable as in your sample data, you can do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    if _N_=1 then do;
        declare hash h1(dataset:"ads(where=(ecs=1 &amp;amp; flag1='Y'))");
        h1.definekey('ID');
        h1.definedone();
        declare hash h2(dataset:"ads(where=(ecs ne 1 &amp;amp; flag1='Y'))");
        h2.definekey('ID');
        h2.definedone();
    end;

    set ads;

    if h1.check()=0 &amp;amp; h2.check()=0 then flag2='Y';
                                   else flag2='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Sep 2019 12:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587217#M167696</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-09T12:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need to make a flag for id which has first flag as Y</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587220#M167698</link>
      <description>&lt;P&gt;Here is a non hash approach that does not depend on the ecs variable, but requires that your data is sorted by ID&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    do until (last.ID);
        set ads;
        by ID;
        if first.ID then _iorc_=ifn(flag1='Y', 1, 0);
        if first.ID ne 1 &amp;amp; _iorc_=1 &amp;amp; flag1='Y' then flag2='Y';
        else                                         flag2='N';
    end;
    do until (last.ID);
        set ads;
        by ID;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID  ecs par   flag1  flag2
12  1   par1  Y      Y
12  2   par1  Y      Y
12  3   par1  Y      Y
12  4   par2  Y      Y
13  1   par1         N
13  2   par1  Y      N
13  3   par1  N      N
13  4   par2  Y      N
14  1   par1  N      N&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 07:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-make-a-flag-for-id-which-has-first-flag-as-Y/m-p/587220#M167698</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-10T07:03:41Z</dc:date>
    </item>
  </channel>
</rss>

