<?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: how to give a value to a flag variable. like when flag=0 then lag(flag)=yes in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922546#M45847</link>
    <description>Please share the log.&lt;BR /&gt;Also, I see you are mixing numerical and character missing calue for your flag variable, stick to char.&lt;BR /&gt;Then you shoudl only do lag() when it's not first.usubjid, otherswise it will cross BY groups.</description>
    <pubDate>Tue, 02 Apr 2024 13:34:39 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2024-04-02T13:34:39Z</dc:date>
    <item>
      <title>how to give a value to a flag variable. like when flag=0 then lag(flag)=yes</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922544#M45846</link>
      <description>&lt;P&gt;I have this raw data,&amp;nbsp; actually , need create a new var, named flag. Only give flag a value when each AVALC=Y and next AVALC=N&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input usubjid $ ADY AVALC $;&lt;BR /&gt;datalines;&lt;BR /&gt;A 15 N&lt;BR /&gt;A 36 N&lt;BR /&gt;A 57 Y&lt;BR /&gt;A 60 N&lt;BR /&gt;A 61 Y&lt;BR /&gt;A 62 N&lt;BR /&gt;A 63 Y&lt;BR /&gt;A 64 Y&lt;BR /&gt;A 65 Y&lt;BR /&gt;B 15 Y&lt;BR /&gt;B 36 Y&lt;BR /&gt;B 57 N&lt;BR /&gt;B 58 N&lt;BR /&gt;B 60 Y&lt;BR /&gt;; run;&lt;/P&gt;&lt;P&gt;output like below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;usubjid $ ADY&amp;nbsp; AVALC&amp;nbsp; FLAG $;&lt;BR /&gt;&lt;BR /&gt;A 15 N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;BR /&gt;A 36 N&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;BR /&gt;A 57 Y CHECK&lt;BR /&gt;A 60 N&amp;nbsp; &amp;nbsp; .&lt;BR /&gt;A 61 Y CHECK&lt;BR /&gt;A 62 N&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;A 63 Y&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;A 64 Y&amp;nbsp; .&amp;nbsp;&lt;BR /&gt;A 65 Y&amp;nbsp; .&lt;BR /&gt;B 15 Y&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;B 36 Y CHECK&lt;BR /&gt;B 57 N&amp;nbsp; .&amp;nbsp;&lt;BR /&gt;B 58 N&amp;nbsp; .&lt;BR /&gt;B 60 Y&amp;nbsp; .&lt;BR /&gt;; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try this code below, the first code, it marked the N,&amp;nbsp; with flat=o, then i want to give the flag before it the value'check' but faile.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA FLAG;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;BY usubjid;&lt;BR /&gt;length flag $6.;&lt;BR /&gt;retain flag;&lt;BR /&gt;if first.usubjid then flag = .;&lt;BR /&gt;IF  AVALC = 'N' and lag(AVALC) = 'Y' then FLAG='o';&lt;BR /&gt;ELSE FLAG=' ';&lt;BR /&gt;RUN;&lt;BR /&gt;data flag1;&lt;BR /&gt;set flag;&lt;BR /&gt;BY usubjid;&lt;BR /&gt;if flag='o' then lag(flag)='check';&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922544#M45846</guid>
      <dc:creator>lindamtl</dc:creator>
      <dc:date>2024-04-02T13:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to give a value to a flag variable. like when flag=0 then lag(flag)=yes</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922546#M45847</link>
      <description>Please share the log.&lt;BR /&gt;Also, I see you are mixing numerical and character missing calue for your flag variable, stick to char.&lt;BR /&gt;Then you shoudl only do lag() when it's not first.usubjid, otherswise it will cross BY groups.</description>
      <pubDate>Tue, 02 Apr 2024 13:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922546#M45847</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-04-02T13:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to give a value to a flag variable. like when flag=0 then lag(flag)=yes</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922549#M45848</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
	by usubjid descending ady;
run;

DATA FLAG;
	SET HAVE;
	BY usubjid;
	length flag $6.;
	if first.usubjid then flag = ' ';
	else IF  AVALC = 'Y' and lag(AVALC) = 'N' then FLAG='check';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922549#M45848</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-04-02T13:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to give a value to a flag variable. like when flag=0 then lag(flag)=yes</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922552#M45849</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input usubjid $ ADY AVALC $;
datalines;
A 15 N
A 36 N
A 57 Y
A 60 N
A 61 Y
A 62 N
A 63 Y
A 64 Y
A 65 Y
B 15 Y
B 36 Y
B 57 N
B 58 N
B 60 Y
; run;



data _null_;
  call symputX("N",nobs,"G");
  stop;
  set have nobs=nobs;
run;

data want;

array test[&amp;amp;n.] $ 1 _temporary_;
do _N_=1 to &amp;amp;n.;
  set have curobs=curobs;
  test[curobs]=AVALC;
end;

do _N_=1 to &amp;amp;n.;
  set have curobs=curobs;
  by usubjid;

  if not last.usubjid then
    do;
      if AVALC="Y" and test[curobs+1]="N" then flag="CHECK";
      else flag=" ";
    end;
  else flag=" ";
  output;
end;

stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922552#M45849</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-02T13:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to give a value to a flag variable. like when flag=0 then lag(flag)=yes</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922553#M45850</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge 
    have 
    have(firstobs=2 
         keep=usubjid AVALC 
         rename=(AVALC=NEXT_AVALC usubjid=NEXT_usubjid)
        );

  if usubjid=NEXT_usubjid 
     and
     AVALC="Y" and NEXT_AVALC="N" then flag="CHECK";
  drop NEXT_:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/how-to-give-a-value-to-a-flag-variable-like-when-flag-0-then-lag/m-p/922553#M45850</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-04-02T13:53:25Z</dc:date>
    </item>
  </channel>
</rss>

