/*----------------------------------------------------------------------------- File: DenullifyDataset.sas Author: John Sabel Washington State Education Research & Data Center Creation date: 2011-09-22 Version: 1.0 Purpose Sets to empty all text fields in a dataset are equal to a given value. For example, this macro can be used to set all instances of "NULL" to the empty string (''); An commented out example is available at the bottom of this file. It contains sample data and a call to the macro. Parameters DsnIn: The one or two-level name of the input dataset. DsnOut: The one or two-level name of the output dataset. SetToEmpty: The character string that is compared with each text field. If a text field is equal to this parameter, the text field is then set to empty (''). Default value is NULL. Debug (Optional) When Debug=Y, the input parameter values are printed to the log. Signature %DenullifyDataset(DsnIn=, DsnOut=, SetToEmpty=NULL, Debug=N) Revisions Date Version Author Comments 2015-05-08 1.0 John More elegant way if implementing logic. -----------------------------------------------------------------------------*/ %macro DenullifyDataset(DsnIn=, DsnOut=, SetToEmpty=NULL, Debug=N); %put --- Start of %upcase(&sysmacroname) macro; %if &Debug.~=N %then %put _local_; data &DsnOut.; set &DsnIn.; array chars _character_; do over chars; if upcase(strip(chars)) = "%upcase(&SetToEmpty.)" then chars = ''; end; run; %if &Debug.~=N %then %put _local_; %put --- End of %upcase(&sysmacroname) macro; %mend; /* data SampleNameData; input ID FirstName $ MiddleName $ Gender $; datalines; 1 John Q M 2 Jack NULL M 3 Jill A F 4 Joshua NULL NULL 5 NULL Adam M 6 Janice O F 7 June NULL F 7 NULL NULL NULL 9 Jenn C F ; run; %DenullifyDataset(DsnIn=SampleNameData, DsnOut=SampleNameData_Out, SetToEmpty=NULL) */