<?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: Writing information about blank records to new dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771979#M245054</link>
    <description>&lt;P&gt;Assuming all of the datasets have the two variables and start with the same prefix you could use a variation on your attempt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's make some sample data first:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x1(keep=name sex) x2(keep=name sex age);
  set sashelp.class;
  if _n_=3 then sex=' ';
  if _n_=5 then name=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can make a view that will generate 0/1 flags for missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data missing / view=missing;
  set x: (keep=name sex) indsname=indsname;
  dsname=indsname;
  blank_name = missing(name);
  blank_sex = missing(sex);
  blank_name_sex = missing(name) and missing(sex);
  keep dsname blank_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which we can then use PROC SUMMARY to aggregate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=missing nway;
  by dsname;
  var blank_:;
  output out=summary sum= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                                      blank_    blank_     blank_
Obs    dsname     _TYPE_    _FREQ_     name       sex     name_sex

 1     WORK.X1       0        19         1         1          0
 2     WORK.X2       0        19         1         1          0
&lt;/PRE&gt;
&lt;P&gt;With a little finagling you can get the result in one step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
  set x: (keep=name sex) indsname=indsname end=eof;
  if indsname ne lag(indsname) and _n_&amp;gt;1 then do;
     output;
     call missing(blank_name,blank_sex,blank_name_sex);
  end;
  dsname=indsname;
  retain dsname;
  blank_name + missing(name);
  blank_sex + missing(sex);
  blank_name_sex + missing(name) and missing(sex);
  if eof then output;
  keep dsname blank_: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;       blank_    blank_     blank_
Obs     name       sex     name_sex    dsname

 1        1         1          0       WORK.X1
 2        1         1          0       WORK.X2
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Oct 2021 18:09:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-10-04T18:09:53Z</dc:date>
    <item>
      <title>Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771974#M245051</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to search through all the datasets in a specific library to see if two specific columns have blank records, if they do, write to a new file, the name of the dataset(s) with blank records, today's and the number of blank records found per dataset. So the output dataset will have three columns: Dataset name, today's date and number of blank rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am stuck here so far.................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data blankClinicIdNum blankClinic blankIdNum;&lt;BR /&gt;set appl1.s:;&lt;BR /&gt;runDate=today();&lt;BR /&gt;format runDate date9.;&lt;BR /&gt;put dt ;&lt;BR /&gt;if clinic =. and idnum =. then output blankClinicIdNum;&lt;BR /&gt;if clinic =. then output blankClinic;&lt;BR /&gt;if idnum =. then output blankIdNum;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 17:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771974#M245051</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-10-04T17:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771976#M245053</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data missingData;
set appl1.s: indsname =source;;
runDate=today();
format runDate date9.;

datasetName = source;

Missing_CLINIC_ID=0; MISSING_CLINIC=0; MISSING_ID=0;

if clinic =. and idnum =. then Missing_Clinic_ID = 1;
if clinic =. then MISSING_CLINIC=1;
if idnum =. then MISSING_ID=1;
run;

proc means data=missingData N SUM MEAN;
class datasetName runDate;
var MISSING_:;
output out summary = want;
run;

proc print data=want;
label N = "# of Observations'
SUM = '# Missing'
MEAN = '% Missing';
format mean percent12.1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An alternative approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364982"&gt;@nduksy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to search through all the datasets in a specific library to see if two specific columns have blank records, if they do, write to a new file, the name of the dataset(s) with blank records, today's and the number of blank records found per dataset. So the output dataset will have three columns: Dataset name, today's date and number of blank rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am stuck here so far.................&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data blankClinicIdNum blankClinic blankIdNum;&lt;BR /&gt;set appl1.s:;&lt;BR /&gt;runDate=today();&lt;BR /&gt;format runDate date9.;&lt;BR /&gt;put dt ;&lt;BR /&gt;if clinic =. and idnum =. then output blankClinicIdNum;&lt;BR /&gt;if clinic =. then output blankClinic;&lt;BR /&gt;if idnum =. then output blankIdNum;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 17:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771976#M245053</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-04T17:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771979#M245054</link>
      <description>&lt;P&gt;Assuming all of the datasets have the two variables and start with the same prefix you could use a variation on your attempt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's make some sample data first:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x1(keep=name sex) x2(keep=name sex age);
  set sashelp.class;
  if _n_=3 then sex=' ';
  if _n_=5 then name=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can make a view that will generate 0/1 flags for missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data missing / view=missing;
  set x: (keep=name sex) indsname=indsname;
  dsname=indsname;
  blank_name = missing(name);
  blank_sex = missing(sex);
  blank_name_sex = missing(name) and missing(sex);
  keep dsname blank_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which we can then use PROC SUMMARY to aggregate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=missing nway;
  by dsname;
  var blank_:;
  output out=summary sum= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                                      blank_    blank_     blank_
Obs    dsname     _TYPE_    _FREQ_     name       sex     name_sex

 1     WORK.X1       0        19         1         1          0
 2     WORK.X2       0        19         1         1          0
&lt;/PRE&gt;
&lt;P&gt;With a little finagling you can get the result in one step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
  set x: (keep=name sex) indsname=indsname end=eof;
  if indsname ne lag(indsname) and _n_&amp;gt;1 then do;
     output;
     call missing(blank_name,blank_sex,blank_name_sex);
  end;
  dsname=indsname;
  retain dsname;
  blank_name + missing(name);
  blank_sex + missing(sex);
  blank_name_sex + missing(name) and missing(sex);
  if eof then output;
  keep dsname blank_: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;       blank_    blank_     blank_
Obs     name       sex     name_sex    dsname

 1        1         1          0       WORK.X1
 2        1         1          0       WORK.X2
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 18:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771979#M245054</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-04T18:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771983#M245055</link>
      <description>&lt;P&gt;You don't say what you are actually stuck on ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that you want to add the INDSNAME option to capture the data set contributing to the current record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data blankClinicIdNum blankClinic blankIdNum;
set appl1.s: INDSNAME=DSN;
   Datasetname=DSN;
   runDate=today();
   format runDate date9.;
   put dt ;/* what is this for???*/
   if clinic =. and idnum =. then output blankClinicIdNum;
   if clinic =. then output blankClinic;
   if idnum =. then output blankIdNum;
run;&lt;/PRE&gt;
&lt;P&gt;The INDSNAME option on the SET statement creates a temporary variable holding the name, library and dataset, of the data set providing the current record. To have the value in the output data set you need to assign it to a permanent variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THEN you use something like Proc Freq, SQL , Means or Summary to count the combinations of datasetname and date.&lt;/P&gt;
&lt;P&gt;If you want the counts of blankclinic and blankidnum in the same data set then combine (merge or join) the count data sets by datasetname and date (though the dates should be the same at this point) if you ever have these created on different dates..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 18:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/771983#M245055</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-04T18:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/772003#M245063</link>
      <description>Thank you! This had everything I wanted and more.</description>
      <pubDate>Mon, 04 Oct 2021 20:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/772003#M245063</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-10-04T20:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/772217#M245178</link>
      <description>&lt;P&gt;Hi Sorry to bother you again. I want to be able to run the program repeatedly without updating the "runDate". Let me explain further - it is possible for the program to be ran today and 1 blank row is returned for dataset X and tomorrow when it is run, same dataset X now has two blank rows. I want to be able to report both occurrences as separate rows, but with different run dates. see sample table below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;Dataset Name&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;Run Date&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;s123&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;04OCT2021&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;s123&lt;/TD&gt;
&lt;TD&gt;05OCT2021&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks as always!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 16:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/772217#M245178</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-10-05T16:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Writing information about blank records to new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/772222#M245181</link>
      <description>So you want to append your results to a data set each time you run it. What happens if the run fails? What happens if you run it mulitple times in one day?&lt;BR /&gt;&lt;BR /&gt;Here's a rough example of how I usually handle these.&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/353374a5d8ea4f0c89ce5d80a47f4a4c" target="_blank"&gt;https://gist.github.com/statgeek/353374a5d8ea4f0c89ce5d80a47f4a4c&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Oct 2021 16:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-information-about-blank-records-to-new-dataset/m-p/772222#M245181</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-05T16:42:00Z</dc:date>
    </item>
  </channel>
</rss>

