<?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: Check if a variable is in sequential order for each vaccination. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909837#M358832</link>
    <description>&lt;P&gt;Please provide an example of your data as shown&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Create-Flag-variable-for-Single-column-data/m-p/857833/highlight/true#M338959" target="_blank" rel="noopener"&gt;here&lt;/A&gt;, and show the expected result.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2023 12:52:26 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-12-28T12:52:26Z</dc:date>
    <item>
      <title>Check if a variable is in sequential order for each vaccination.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909836#M358831</link>
      <description>&lt;P&gt;Please help me to write a code to check if a variable is in sequential order for each vaccination. I am a new SAS programmer.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 12:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909836#M358831</guid>
      <dc:creator>AwesomeSAS</dc:creator>
      <dc:date>2023-12-28T12:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a variable is in sequential order for each vaccination.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909837#M358832</link>
      <description>&lt;P&gt;Please provide an example of your data as shown&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Create-Flag-variable-for-Single-column-data/m-p/857833/highlight/true#M338959" target="_blank" rel="noopener"&gt;here&lt;/A&gt;, and show the expected result.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 12:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909837#M358832</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-28T12:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a variable is in sequential order for each vaccination.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909859#M358834</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439327"&gt;@AwesomeSAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please help me to write a code to check if a variable is in sequential order for each vaccination. I am a new SAS programmer.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which variable?&amp;nbsp; What does a "vaccination" mean?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by sequential order?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that you mean you have some variable, let's call it VAX, that defines groups of observations and you want to check if some other variable, let's call it OTHER, is monotonically increasing by one for each observation in the group then you probably want something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by VAX ;
  diff = dif(other);
  if first.vax then diff=.;
  else if diff ne 1 then put 'WARNING: Non sequential value. ' _n_= VAX= OTHER= DIFF= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 16:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909859#M358834</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-28T16:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a variable is in sequential order for each vaccination.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909875#M358840</link>
      <description>&lt;P&gt;You need to describe what you have and what you want a bit more and also provide some sample data if you're after code.&lt;/P&gt;
&lt;P&gt;It's normally also appreciate if you share some of the code you already tried whether it's working or not. Such code still helps us to understand your thinking and on what coding level you are so we can give you answers on an appropriate level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I couldn't resist to copy/paste your question into chatGPT. It didn't return valid code but it did create sample data and the code was close enough for a quick fix.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vaccinations;
  input patient_id vaccination_date:yymmdd10.;
  format vaccination_date date9.;
  datalines;
1 2023-01-01
1 2023-02-01
1 2023-03-01
2 2023-01-15
2 2023-02-15
3 2023-01-10
3 2023-02-10
3 2023-02-09
3 2023-03-10
;

data check_sequential;
  set vaccinations;
  by patient_id;
  sequential_order_flag= ( first.patient_id or vaccination_date &amp;gt;= lag(vaccination_date) );
run;

proc print data=check_sequential;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1703806289917.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92121iB758AEBFEA63A9E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1703806289917.png" alt="Patrick_0-1703806289917.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To populate the flag variable above code takes advantage that SAS returns 1 if a logical expression is TRUE and 0 if it's FALSE.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1703806767873.png" style="width: 564px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92122i2EDE1E1ACBF30D9B/image-dimensions/564x27?v=v2" width="564" height="27" role="button" title="Patrick_0-1703806767873.png" alt="Patrick_0-1703806767873.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The expression becomes TRUE if it's a new patient_id - FIRST.patient_id - OR if the vaccination_date is greater or equal compared to the vaccination_date of the previous row - LAG(vaccination_date)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 23:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-variable-is-in-sequential-order-for-each-vaccination/m-p/909875#M358840</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-28T23:46:38Z</dc:date>
    </item>
  </channel>
</rss>

