<?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: Output missing values between two lists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872779#M344815</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Animal $ Days :$10. Days_expected :$10.;
cards;
100            1,2,3,4         1,2,3,4,5
101            2,3,5            1,2,3,4,5
102            1,3,4,5         1,2,3,4,5
;
data want;
 set have;
 Days_missing=prxchange(cats('s/\b(',translate(Days,'|',','),')\b//'),-1,Days_expected);
 Days_missing=prxchange('s/^,+|,+$//',-1,strip(Days_missing));
 Days_missing=prxchange('s/,+/,/',-1,Days_missing);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Apr 2023 11:09:09 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-04-28T11:09:09Z</dc:date>
    <item>
      <title>Output missing values between two lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872628#M344750</link>
      <description>&lt;P&gt;I have two variables that should match, but some do not.&amp;nbsp; The variables are comma separated strings and if one list is missing values from the ideal list, I need it to output those values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&lt;/P&gt;&lt;P&gt;Animal&amp;nbsp; &amp;nbsp; &amp;nbsp; Days&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Days_expected&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,2,3,4,5&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2,3,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,4,5&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,3,4,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,2,3,4,5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;Animal&amp;nbsp; &amp;nbsp; &amp;nbsp; Days&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Days_expected&amp;nbsp; &amp;nbsp; &amp;nbsp;Days_missing&lt;/P&gt;&lt;P&gt;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,2,3,4,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2,3,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,4,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,4&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,3,4,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,2,3,4,5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 18:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872628#M344750</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-04-27T18:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Output missing values between two lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872632#M344752</link>
      <description>&lt;P&gt;Just loop over the set of expected values and test if it appears or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Animal $ Days :$10. Days_expected :$10.;
cards;
100            1,2,3,4         1,2,3,4,5
101            2,3,5            1,2,3,4,5
102            1,3,4,5         1,2,3,4,5
;

data want;
  set have;
  length Days_missing $10;
  do index=1 to countw(days_expected,',');
    if not findw(days,scan(days_expected,index,','),',','T') then
      days_missing=catx(',',days_missing,scan(days_expected,index,','))
    ;
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Apr 2023 18:36:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872632#M344752</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-27T18:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Output missing values between two lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872641#M344760</link>
      <description>&lt;P&gt;Generally placing multiple values into a single variable is a bad thing and this is an example.&lt;/P&gt;
&lt;P&gt;Questions: Does the value of "Days_expected" ever actually change? Is it actually a variable in the dataset? If so, is it always going to be sequentially numbered values?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the example provided:&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines dlm='|';
   input Animal $ Days:$15. Days_expected :$15. ;
   length word $ 3 result $ 15;
   do i=1 to countw(days_expected,',');
      word = scan(days_expected,i,',');
      if findw(strip(days), strip(word),',')=0 
          then result=catx(',',result, word);
   end;
   drop i word;
datalines;
100|1,2,3,4|1,2,3,4,5
101|2,3,5|1,2,3,4,5
102|1,3,4,5|1,2,3,4,5
;&lt;/PRE&gt;
&lt;P&gt;Strip is needed in a few places because we do not know the actual lengths of your variables or the maximum possible value(s) involved.&lt;/P&gt;
&lt;P&gt;Countw counts how many elements are in the list. If Days_expected is not an actual variable then use a quoted list such as "1,2,3,4,5" every where the variable Days_expected appears.&lt;/P&gt;
&lt;P&gt;Scan pulls out the word. Findw finds if a word matches in the first value. If not the returned value is 0 so we add the word to the Result list. Catx places a comma between the words.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872641#M344760</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-27T19:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Output missing values between two lists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872779#M344815</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Animal $ Days :$10. Days_expected :$10.;
cards;
100            1,2,3,4         1,2,3,4,5
101            2,3,5            1,2,3,4,5
102            1,3,4,5         1,2,3,4,5
;
data want;
 set have;
 Days_missing=prxchange(cats('s/\b(',translate(Days,'|',','),')\b//'),-1,Days_expected);
 Days_missing=prxchange('s/^,+|,+$//',-1,strip(Days_missing));
 Days_missing=prxchange('s/,+/,/',-1,Days_missing);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 11:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-missing-values-between-two-lists/m-p/872779#M344815</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-04-28T11:09:09Z</dc:date>
    </item>
  </channel>
</rss>

