<?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: Fill missing values in all variables of a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728611#M226707</link>
    <description>&lt;P&gt;In case you just want to do this for reporting purposes then consider to not change the data but to use formats and/or options missing='#'; instead.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 00:52:26 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-03-24T00:52:26Z</dc:date>
    <item>
      <title>Fill missing values in all variables of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728592#M226705</link>
      <description>&lt;P&gt;I need some code that will loop through all variables in a dataset, and check each variable for missing values.&lt;/P&gt;&lt;P&gt;If any missing are found then fill with # characters (or value 9) based on the length of that particular variable.&lt;/P&gt;&lt;P&gt;Here is my poor attempt:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
dsid=open("have", "i"); 
n_vars=attrn(dsid, "nvars");
do i=1 to n_vars;
Name=varname(dsid, i);
Type=vartype(dsid, i);

set have;

if missing(Name) then do;
	if Type = 'C' then 
		Name = repeat('#', length(Name));
	else	
		Name = repeat(9, length(Name));
	end; 

end;
rc=close(dsid);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Mar 2021 22:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728592#M226705</guid>
      <dc:creator>simmwa</dc:creator>
      <dc:date>2021-03-23T22:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values in all variables of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728600#M226706</link>
      <description>&lt;P&gt;At its very minimum, below should do the job. Also REPEAT function returns a character value so I'd suggest keeping missing numeric values as "99" or "999", below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set sashelp.class;
if name = 'James' then call missing(sex,weight);
run;

%macro test;


%local i;

proc sql;
	select name,type,length
		into: name1 - :name&amp;amp;sysmaxlong, 
		:type1 - :type&amp;amp;sysmaxlong,
		:len1 - :len&amp;amp;sysmaxlong
	from dictionary.columns
		where libname = 'WORK'
			and memname = 'HAVE';
	%let cnt = &amp;amp;sqlobs;
quit;

data want;
	set have;

	%do i = 1 %to &amp;amp;cnt.;
		%if &amp;amp;&amp;amp;type&amp;amp;i. = char %then
			%do;
				if missing(&amp;amp;&amp;amp;name&amp;amp;i.) then
					&amp;amp;&amp;amp;name&amp;amp;i. = repeat('#', &amp;amp;&amp;amp;len&amp;amp;i.);
			%end;
		%else
			%do;
				if missing(&amp;amp;&amp;amp;name&amp;amp;i.) then
					&amp;amp;&amp;amp;name&amp;amp;i. = 99;

				/*&amp;amp;&amp;amp;name&amp;amp;i. = input(strip(repeat(9, &amp;amp;&amp;amp;len&amp;amp;i.)),8.);*/
			%end;
	%end;
run;

%mend;

%test
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Mar 2021 00:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728600#M226706</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-03-24T00:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values in all variables of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728611#M226707</link>
      <description>&lt;P&gt;In case you just want to do this for reporting purposes then consider to not change the data but to use formats and/or options missing='#'; instead.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 00:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728611#M226707</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-03-24T00:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values in all variables of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728663#M226715</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/246836"&gt;@qoit&lt;/a&gt; it works perfectly !&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 03:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/728663#M226715</guid>
      <dc:creator>simmwa</dc:creator>
      <dc:date>2021-03-24T03:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing values in all variables of a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/740704#M231421</link>
      <description>&lt;P&gt;Is there a way to include a macro for multiple HAVE datasets.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 02:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-values-in-all-variables-of-a-dataset/m-p/740704#M231421</guid>
      <dc:creator>dscastelino</dc:creator>
      <dc:date>2021-05-12T02:57:50Z</dc:date>
    </item>
  </channel>
</rss>

