<?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 non matching string dynamic datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966166#M376045</link>
    <description>&lt;P&gt;Not sure if macros are needed. If you have a number of data sets (do you mean SAS data sets?) and they are all in one library (folder) with some sort of common naming scheme, you should be able to combine them all into one large SAS data set and then just do a loop in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe the location(s) of the data sets, the naming scheme, and what they contain in more detail.&lt;/P&gt;</description>
    <pubDate>Fri, 09 May 2025 15:06:38 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-05-09T15:06:38Z</dc:date>
    <item>
      <title>Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966159#M376042</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;In my task, I have to check if a string present in a dataset with a date (f.e april 30, 2025) is present in the dataset with the previous date (april 29, 2025). This is a dynamic task, so I think I need to use the macro sas code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created one dataset for each date of April (in total, 30 datasets). Then I have to check if a string is matched on the dataset of the previous day and so on for each day of April (maybe something like (df april 30, 2025) left join (df april 29, 2025) where the string is null in&amp;nbsp;(df april 29, 2025)).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any idea/advice about how to do this task?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankss&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 14:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966159#M376042</guid>
      <dc:creator>M_96</dc:creator>
      <dc:date>2025-05-09T14:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966166#M376045</link>
      <description>&lt;P&gt;Not sure if macros are needed. If you have a number of data sets (do you mean SAS data sets?) and they are all in one library (folder) with some sort of common naming scheme, you should be able to combine them all into one large SAS data set and then just do a loop in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe the location(s) of the data sets, the naming scheme, and what they contain in more detail.&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 15:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966166#M376045</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-09T15:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966174#M376047</link>
      <description>&lt;P&gt;I have a SAS dataset like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data data_1apr2025;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;input&amp;nbsp; data date9. tkt $;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;format data date9. ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;datalines;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;01APR2025 3333123&lt;/DIV&gt;&lt;DIV&gt;01APR2025 43333111&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;and then I have:&lt;/DIV&gt;&lt;DIV&gt;data data_2apr2025;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;input&amp;nbsp; data date9. tkt $;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;format data date9. ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;datalines;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;02APR2025 99999999&lt;/DIV&gt;&lt;DIV&gt;02APR2025 43333111&lt;/DIV&gt;&lt;DIV&gt;02APR2025 11111111&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on for all the 30 days of April....&lt;/P&gt;&lt;P&gt;I ned to check if in the dataset&amp;nbsp;data_2apr2025 there are NOT MATCHING TKT with the dataset&amp;nbsp;data_1apr2025.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is what I did with these 2 datasets:&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table not_matching as select distinct a.tkt from data_2apr2025 a left join data_1apr2025b on a.tkt=b.tktwhere b.tktis null;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;The output is:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;02APR2025 99999999&lt;/DIV&gt;&lt;DIV&gt;02APR2025 11111111&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this query works if you have 2 static dataset; in my task, I need to loop the query for each day of April and comparing it with the previous day.&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 16:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966174#M376047</guid>
      <dc:creator>M_96</dc:creator>
      <dc:date>2025-05-09T16:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966180#M376050</link>
      <description>&lt;P&gt;Okay, it helps to see what you are working with. I think a macro is required here. You make things harder by using data set names that don't sort alphabetically, a data set named _20250401 for April 1 would at least sort properly, across months and within months, but maybe that doesn't even matter to produce the SAS code for this problem, but it might matter when you go ahead and try to use these datasets somehow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_this;
    %do date=%sysfunc(mdy(4,2,2025)) %to %sysfunc(mdy(4,30,2025));     
        %let previous_day=%eval(&amp;amp;date-1);
        %let date1=%sysfunc(putn(&amp;amp;date,date9.));
        %let previous_day1=%sysfunc(putn(&amp;amp;previous_day,date9.));
        /* Remove leading zero from dates */
        %if %substr(&amp;amp;date1,1,1)=0 %then %let date1=%substr(&amp;amp;date1,2);
        %if %substr(&amp;amp;previous_day1,1,1)=0 %then %let previous_day=%substr(&amp;amp;previous_day1,2);
        proc sql;
            create table not_matching_&amp;amp;date1 as select distinct a.tkt 
            from data_&amp;amp;date1 a
                  left join data_&amp;amp;previous_day1 b on a.tkt=b.tkt where b.tktis null;
        quit;
    %end;
%mend;
%do_this&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 18:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966180#M376050</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-09T18:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966220#M376074</link>
      <description>&lt;P&gt;Here could give you a start.&lt;/P&gt;
&lt;P&gt;And you could use CALL EXECUTE to go through macro %check()&amp;nbsp; with all the date of April .&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data data_1apr2025;
input  data date9. tkt $;
format data date9. ;
datalines;
01APR2025 3333123
01APR2025 43333111
;
RUN;
 
data data_2apr2025;
input  data date9. tkt $;
format data date9. ;
datalines;
02APR2025 99999999
02APR2025 43333111
02APR2025 11111111
;
RUN;


%macro check(date=);
proc sql;
create table want_&amp;amp;date. as
select * from data_&amp;amp;date. 
 where tkt not in (select distinct tkt
  from data_%sysfunc(prxchange(s/^0//,1,%sysfunc(intnx(day,"&amp;amp;date."d,-1),date9.)) ));
quit;
%mend;

%check(date=2apr2025)&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 May 2025 02:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966220#M376074</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-10T02:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966247#M376079</link>
      <description>&lt;P&gt;If you want to compare the values of a variable (whether it is character or numeric) between two datasets a MERGE is a good method.&amp;nbsp; Make sure the data is sorted by the variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_1apr2025;
  input data :date. tkt $;
  format data date9. ;
datalines;
01APR2025 3333123
01APR2025 43333111
;
data data_2apr2025;
  input data :date. tkt $;
  format data date9. ;
datalines;
02APR2025 11111111
02APR2025 43333111
02APR2025 99999999
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can merge and use the IN= dataset option to check if the values exists in both datasets or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge data_1apr2025(in=in1) data_2apr2025(in=in2);
  by tkt;
  if not (in1 and in2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;OBS         data      tkt

 1     02APR2025    11111111
 2     01APR2025    3333123
 3     02APR2025    99999999
&lt;/PRE&gt;
&lt;P&gt;If you don't want that second mismatch for some reason then just change the criteria.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if in2 and not in1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But since you also have the DATE (named DATA for some reason) in the dataset perhaps it would be easier to interleave the datasets instead?&amp;nbsp; Then the check for a mismatch is just whether there is more than one observation. So the IN= dataset option is not needed.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set data_1apr2025 data_2apr2025;
  by tkt data;
  if (first.tkt and last.tkt);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps you&amp;nbsp; want to find the places where there is a gap in the appearance of TKT for one or more dates?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_3apr2025;
  input data :date. tkt $;
  format data date9. ;
datalines;
03APR2025 3333123
03APR2025 43333111
;

data want;
  set data_: ;
  by tkt data;
  lag_data=lag(data);
  format lag_data date9.;
  if (not first.tkt) and (data-1 ne lag(data));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;OBS         data      tkt       lag_data

 1     03APR2025    3333123    01APR2025

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 May 2025 18:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966247#M376079</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-10T18:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Check non matching string dynamic datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966249#M376080</link>
      <description>&lt;P&gt;You could compare two daily datasets at a time, but that would mean processing most of the datasets twice, once as the "before" date, and once as the "after".&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if each of the datasets are sorted by TKT, then you could process all of the datasets in a single pass.&amp;nbsp; Something like (I have changed the daily dataset names to&amp;nbsp; DATA_20250401, DATA_20250402, ... DATA_20250430):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set data_202504: ;
  by tkt descending date;
  if first.tkt=0 and dif(date)^=-1 then output;
  else if first.tkt=1 and date^='30apr2025'd then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data are not sorted by TKT and if sorting would be expensive, then read the datasets in reverse chronological order.&amp;nbsp; You could use two hash objects to hold current and next daily data (NEXTDAY in the code below). If an incoming observation has a TKT not found in the NEXTDAY object, then output it.&amp;nbsp; At the end of each day,&amp;nbsp;clear the NEXTDAY object and copy the CURRDAY data into it, in preparation for new current date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set data_202504: ;
  by descending date;
  if _n_=1 then do;
    declare hash currday();
      currday.definekey('tkt');
      currday.definedata('tkt','date');
      currday.definedone();
    declare hiter i ('currday');

    declare hash nextday();
      nextday.definekey('tkt');
      nextday.definedata('tkt','date');
      nextday.definedone();
  end;

  if date='30apr2025'd then do; 
    nextday.add();
    return;
  end;
  currday.add();

  if nextday.check()^=0 then output;

  if last.date then do;
    /*Replace NEXTDAY with CURRDAY hash object */
    nextday.clear();
    do while (i.next()=0);
      nextday.add();
    end;
    currday.clear();
  end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note these programs assume there are no duplicate TKT values within each daily dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 11 May 2025 02:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-non-matching-string-dynamic-datasets/m-p/966249#M376080</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-05-11T02:28:39Z</dc:date>
    </item>
  </channel>
</rss>

