<?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: Keep accounts that had missing value for a variable in one month but not missing in previous mon in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674427#M203098</link>
    <description>&lt;P&gt;Join the dataset with itself:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select distinct a.account_id
  from have a, have b
  where
    a.account_id = b.account_id and
    put(a.run_date,yymmn6.) = '202006' and
    a.score ne . and
    put(b.run_date,yymmn6.) = '202007' and
    b.score = .
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply usable example data in a data step with datalines.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Aug 2020 16:24:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-08-04T16:24:49Z</dc:date>
    <item>
      <title>Keep accounts that had missing value for a variable in one month but not missing in previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674421#M203093</link>
      <description>&lt;P&gt;Hi, I've got &lt;U&gt;&lt;STRONG&gt;one dataset&lt;/STRONG&gt;&lt;/U&gt; that contains three variables:&lt;/P&gt;&lt;P&gt;1. ACCOUNT_ID (Type: Numeric, Format: 13.)&lt;/P&gt;&lt;P&gt;2. RUN_DATE (Type: Numeric, Group: Date, Format: DATE9.)&lt;/P&gt;&lt;P&gt;3. SCORE (Type: Character)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my dataset, ac.test, I would like to create another dataset with all of the the account ID that had a &lt;U&gt;&lt;STRONG&gt;missing&lt;/STRONG&gt; SCORE value in &lt;STRONG&gt;July 2020&lt;/STRONG&gt;&lt;/U&gt;, but &lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt; missing in &lt;STRONG&gt;June 2020&lt;/STRONG&gt;&lt;/U&gt;. Can someone help provide me with code to answer the question, so the &lt;U&gt;&lt;STRONG&gt;new dataset&lt;/STRONG&gt;&lt;/U&gt; should contain account ID's where this is the case, as well as all its RUN_DATE and SCORE information &lt;U&gt;&lt;STRONG&gt;from June 2020&lt;/STRONG&gt;&lt;/U&gt;? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset contains over 500,000 records, so the code would ideally work for the entire dataset. The screenshots below are just an example (so the dataset would keep accounts that had a missing SCORE value in July, but not missing in June - in the example, the new dataset would contain 16211274,&amp;nbsp;16211277 and&amp;nbsp;16211278, as well as its RUN_DATE and SCORE values).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I only have &lt;U&gt;&lt;STRONG&gt;one dataset&lt;/STRONG&gt;&lt;/U&gt;, and the lines are just to separate June and July 2020 in this example:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Score query.JPG" style="width: 292px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/47917iF40E792EF5D3B192/image-size/large?v=v2&amp;amp;px=999" role="button" title="Score query.JPG" alt="Score query.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Justin9_0-1596558183373.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/47918iC74D52A76C06FCD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Justin9_0-1596558183373.png" alt="Justin9_0-1596558183373.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674421#M203093</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2020-08-04T16:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Keep accounts that had missing value for a variable in one month but not missing in previous mon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674427#M203098</link>
      <description>&lt;P&gt;Join the dataset with itself:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select distinct a.account_id
  from have a, have b
  where
    a.account_id = b.account_id and
    put(a.run_date,yymmn6.) = '202006' and
    a.score ne . and
    put(b.run_date,yymmn6.) = '202007' and
    b.score = .
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply usable example data in a data step with datalines.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674427#M203098</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T16:24:49Z</dc:date>
    </item>
    <item>
      <title>Keep accounts with missing value for variable in one month but not missing in previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674439#M203110</link>
      <description>&lt;P&gt;Hi, I've got &lt;U&gt;&lt;STRONG&gt;one dataset&lt;/STRONG&gt;&lt;/U&gt; that contains three variables:&lt;/P&gt;&lt;P&gt;1. ACCOUNT_ID (Type: Numeric, Format: 13.)&lt;/P&gt;&lt;P&gt;2. RUN_DATE (Type: Numeric, Group: Date, Format: DATE9.)&lt;/P&gt;&lt;P&gt;3. SCORE (Type: Character)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my dataset, ac.test, I would like to create another dataset with all of the the account ID that had a &lt;U&gt;&lt;STRONG&gt;missing&lt;/STRONG&gt; SCORE value in &lt;STRONG&gt;July 2020&lt;/STRONG&gt;&lt;/U&gt;, but &lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt; missing in &lt;STRONG&gt;June 2020&lt;/STRONG&gt;&lt;/U&gt;. Can someone help provide me with code to answer the question, so the &lt;U&gt;&lt;STRONG&gt;new dataset&lt;/STRONG&gt;&lt;/U&gt; should contain account ID's where this is the case, as well as all its RUN_DATE and SCORE information &lt;U&gt;&lt;STRONG&gt;from June 2020&lt;/STRONG&gt;&lt;/U&gt;? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset contains over 500,000 records, so the code would ideally work for the entire dataset. The screenshots below are just an example (so the dataset would keep accounts that had a missing SCORE value in July, but not missing in June - in the example, the new dataset would contain 16211274,&amp;nbsp;16211277 and&amp;nbsp;16211278, as well as its RUN_DATE and SCORE values).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I only have &lt;U&gt;&lt;STRONG&gt;one dataset&lt;/STRONG&gt;&lt;/U&gt;, and the lines are just to separate June and July 2020 in this example:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Score query.JPG" style="width: 292px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/47917iF40E792EF5D3B192/image-size/large?v=v2&amp;amp;px=999" role="button" title="Score query.JPG" alt="Score query.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Justin9_0-1596558183373.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/47918iC74D52A76C06FCD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Justin9_0-1596558183373.png" alt="Justin9_0-1596558183373.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674439#M203110</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2020-08-04T16:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Keep accounts with missing value for variable in one month but not missing in previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674442#M203111</link>
      <description>&lt;P&gt;Please do not double-post; instead read the answers that were given before replying yourself.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674442#M203111</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T16:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Keep accounts that had missing value for a variable in one month but not missing in previous mon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674443#M203112</link>
      <description>&lt;P&gt;Thanks for your reply. I've edited my post slightly - I've only got one dataset (that contains both June 2020 and July 2020) and the SCORE is a character variable, so I've edited the code you provided but the new output table doesn't give me the results as intended (how I want it to look in my example). Would it be possible to advise me on where I've gone wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table analysis as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;select distinct ACCOUNT_ID&lt;/P&gt;&lt;P&gt;&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;,RUN_DATE&lt;/P&gt;&lt;P&gt;&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;,SCORE&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;from ac.test&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;where (put(RUN_DATE,yymmn6.)='202006' and SCORE ne ' ') and&amp;nbsp;(put(RUN_DATE,yymmn6.)='202007' and SCORE=' ')&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674443#M203112</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2020-08-04T16:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Keep accounts that had missing value for a variable in one month but not missing in previous mon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674456#M203122</link>
      <description>&lt;P&gt;As stated, the code is not tested. For tested code, supply example data in usable form.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 17:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674456#M203122</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T17:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Keep accounts with missing value for variable in one month but not missing in previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674457#M203123</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have (where=(run_date between '01jul2020'd and '31jul2020'd and score=.)  in=in1)
        have (where=(run_date between '01jun2020'd and '30jun2020'd and score^=.) in=in2);
  by account_id;
  if in1 and in2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the JULY 2020 filter is the first merge operand, and the JUNE filter is the last.&amp;nbsp; So any common variables will get their values from the JUNE record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes your data are sorted by ID&amp;nbsp; (but not necessarily by run_date within id).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editted addition:&amp;nbsp; But I see that your sample data is sorted by date/id, but &lt;EM&gt;&lt;STRONG&gt;within monthly groupings it appears to effectively sorted by id&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; If so then the above program should still work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if, within each month, date are NOT sorted by id within each month, you would need to pre-sort the records of interest:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=need;
 by account_id run_date;
 where
    (run_date between '01jul2020'd and '31jul2020'd and score=.) 
    or
    (run_date between '01jun2020'd and '30jun2020'd and score^=.) ;
run;
data want;
  set need;
  by account_id;
  if first.account_id=1 and last.account_id=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 17:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674457#M203123</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-04T17:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Keep accounts that had missing value for a variable in one month but not missing in previous mon</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674657#M203170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321018"&gt;@Justin9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply. I've edited my post slightly - I've only got one dataset (that contains both June 2020 and July 2020) and the SCORE is a character variable, so I've edited the code you provided but the new output table doesn't give me the results as intended (how I want it to look in my example). Would it be possible to advise me on where I've gone wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table analysis as&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;select distinct ACCOUNT_ID&lt;/P&gt;
&lt;P&gt;&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;,RUN_DATE&lt;/P&gt;
&lt;P&gt;&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;,SCORE&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;from ac.test&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;where (put(RUN_DATE,yymmn6.)='202006' and SCORE ne ' ') and&amp;nbsp;(put(RUN_DATE,yymmn6.)='202007' and SCORE=' ')&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I explicitly stated in my post that I join the dataset to &lt;STRONG&gt;ITSELF&lt;/STRONG&gt;, so I &lt;U&gt;&lt;EM&gt;am&lt;/EM&gt;&lt;/U&gt; taking into account that you only have one dataset.&lt;/P&gt;
&lt;P&gt;See here the proof that my code works (I just added two columns to the output, changed score to character, and deleted the DISTINCT keyword, as it is not needed):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input account_id $ run_date :date9. score $;
format run_date date9.;
datalines;
16211273 26jun2020 125
16211274 26jun2020 235
16211275 26jun2020 .
16211276 28jun2020 .
16211277 29jun2020 400
16211278 29jun2020 500
16211279 30jun2020 .
16211280 30jun2020 .
16211273 22jul2020 150
16211274 24jul2020 .
16211275 26jul2020 200
16211276 28jul2020 .
16211277 29jul2020 .
16211278 29jul2020 .
16211279 30jul2020 402
16211280 30jul2020 326
;

proc sql;
create table want as
  select a.account_id, a.run_date, a.score
  from have a, have b
  where
    a.account_id = b.account_id and
    put(a.run_date,yymmn6.) = '202006' and
    a.score ne "" and
    put(b.run_date,yymmn6.) = '202007' and
    b.score = ""
;
quit;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;account_id	run_date	score
16211274	26JUN2020	235
16211277	29JUN2020	400
16211278	29JUN2020	500&lt;/PRE&gt;
&lt;P&gt;Note that I had to waste a lot of time typing data off a picture(!). Next time, please provide data as shown in this code, so we can immediately start testing.&lt;/P&gt;
&lt;P&gt;Pictures are the WORST way to present example data, by lunar distances.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 07:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-accounts-that-had-missing-value-for-a-variable-in-one-month/m-p/674657#M203170</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T07:41:29Z</dc:date>
    </item>
  </channel>
</rss>

