<?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: Setting value to 0 if missing - a way to check for all variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630852#M186810</link>
    <description>&lt;P&gt;I think this is along the lines of what I want. Although, when I run the proc sql with my actual data, I get "No rows were selected". Any ideas why? I tried the test data and it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I solved it, the memname has to be in uppercase! Thanks!!&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 10:48:58 GMT</pubDate>
    <dc:creator>UniversitySas</dc:creator>
    <dc:date>2020-03-10T10:48:58Z</dc:date>
    <item>
      <title>Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630827#M186800</link>
      <description>&lt;P&gt;Suppose I have the following data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile DATALINES dsd missover;
input ID Miles Windows Occupants;
CARDS;
01, 100, 2, 5
02, 200, 4, 5
03, 300, 2, .
04, ., 6, 2
05, 500, ., 8
06, 600, ., .
07, 700, 4, 5
08, 800, 4, .
02, 4, 1.7, 3
02, 5, 5.1, 4
;
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;Is there a way for me to check whether any set of variables, excluding another set of variables is missing, and then set that value =0?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance, I want to check if &lt;STRONG&gt;Windows&lt;/STRONG&gt; and &lt;STRONG&gt;Occupants&lt;/STRONG&gt; are missing, but not &lt;STRONG&gt;Miles.&amp;nbsp;&lt;/STRONG&gt;I know how to do this individually, but I have around 50 or so variables I want to check, and 5 I want to exclude, so it would be somewhat tedious to write it all out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile DATALINES dsd missover;
input ID Miles Windows Occupants;
CARDS;
01, 100, 2, 5
02, 200, 4, 5
03, 300, 2, 0
04, ., 6, 2
05, 500, 0, 8
06, 600, 0, 0
07, 700, 4, 5
08, 800, 4, 0
02, 4, 1.7, 3
02, 5, 5.1, 4
;
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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 09:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630827#M186800</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-03-10T09:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630828#M186801</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use an array to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;	
	set temp;
	array _miss (*) Windows Occupants /* NB: reference the variables that are concerned or use _numeric_ if you want to refer to all numeric variables*/;
	do i=1 to dim(_miss);
		if _miss(i) = . then _miss(i) = 0;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 09:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630828#M186801</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-10T09:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630838#M186804</link>
      <description>&lt;P&gt;Alternatively, consider the do over&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set temp;
array mis Windows Occupants;
do over mis;
if mis=. then mis=0;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 10:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630838#M186804</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-03-10T10:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630839#M186805</link>
      <description>Thanks for your response. In your code I can reference the variables I want, or use _Numeric_. Instead, is there a way such that I can reference the variables I do NOT want, and check for all others? This is because I have lots of variables I want, and referencing them separately would be tedious.</description>
      <pubDate>Tue, 10 Mar 2020 10:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630839#M186805</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-03-10T10:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630842#M186807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're welcome!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that you use a macrovariable to retrieve the column name that you want to include in the array statement.&lt;/P&gt;
&lt;P&gt;You just need to adapt the "where" clause in Proc SQL to specify which variables you don't want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select name
	into:mylist separated by " "
	from dictionary.columns
	where libname="WORK" and memname="TEMP" and name not in ("ID" "Miles"); /* -&amp;gt; select your columns*/
quit;

data want;	
	set temp;
	array _miss (*) &amp;amp;mylist;
	do i=1 to dim(_miss);
		if _miss(i) = . then _miss(i) = 0;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 10:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630842#M186807</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-10T10:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630852#M186810</link>
      <description>&lt;P&gt;I think this is along the lines of what I want. Although, when I run the proc sql with my actual data, I get "No rows were selected". Any ideas why? I tried the test data and it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I solved it, the memname has to be in uppercase! Thanks!!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 10:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630852#M186810</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-03-10T10:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630856#M186812</link>
      <description>&lt;P&gt;Awesome!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 10:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630856#M186812</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-10T10:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630858#M186813</link>
      <description>&lt;P&gt;Quick question, if I also wanted to divide this list of variables by their corresponding row entry for another variable, e.g., Miles, can I somehow do it in that data-step?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Got it, in the loop I can just put _miss(i)/miles&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 11:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630858#M186813</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-03-10T11:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630859#M186814</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Quick question, if I also wanted to divide this list of variables by their corresponding row entry for another variable, e.g., Miles, can I somehow do it in that data-step?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Quick answer ... don't do this. If you really need separate analyses for the different values of another variable ... there are better ways to do this such as using formats or using BY variables.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 11:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630859#M186814</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-10T11:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630860#M186815</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95638"&gt;@UniversitySas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do this by adding a statement in the do loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select name
	into:mylist separated by " "
	from dictionary.columns
	where libname="WORK" and memname="TEMP" and name not in ("ID" "Miles"); /* -&amp;gt; select your columns*/
quit;

data want;	
	set temp;
	array _miss (*) &amp;amp;mylist;
	do i=1 to dim(_miss);
		if _miss(i) = . then _miss(i) = 0;
		_miss(i) = _miss(i) / /*your_variable*/;
	end;
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In fact, the array is just a way to repeat the same manipulation on a series of columns.&lt;/P&gt;
&lt;P&gt;In practice, the column can be identify by its position in the array:&lt;/P&gt;
&lt;P&gt;e.g. _miss(1) corresponds to the first column referenced in the array, so Windows&lt;/P&gt;
&lt;P&gt;e.g. _miss(2) corresponds to the second column referenced in the array, so Occupants&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;So instead of writing&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If Windows = . then Windows =0;
Windows = Windows / &amp;nbsp;x;
If Occupants = . then Occupants =0;
Occupant = Occupants / &amp;nbsp;x;&lt;/PRE&gt;
&lt;P&gt;You can write:&lt;/P&gt;
&lt;PRE&gt;If _miss(1) = . then _miss(1) =0;
_miss(1) = _miss(1) / &amp;nbsp;x;
If _miss(2) = . then _miss(2) =0;
_miss(2) = _miss(2) / &amp;nbsp;x;&lt;/PRE&gt;
&lt;P&gt;... and what is better -&amp;gt; loop through the position 1, 2, ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 11:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630860#M186815</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-10T11:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630865#M186818</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=temp out=want reponly missing=0;
var Windows Occupants;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 11:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630865#M186818</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-10T11:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630866#M186819</link>
      <description>&lt;P&gt;Setting values to zero when they are missing seems like a dangerous thing to do, it will change your averages and every other statistic as well. Does it really make any sense to say if Occupants is missing, that's really a zero? Such a modification of the data should only be done if you have a good understanding of each variable and why it might be missing, and without such reasoning, I would not recommend doing this.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 11:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630866#M186819</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-10T11:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Setting value to 0 if missing - a way to check for all variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630905#M186837</link>
      <description>Hi Paige, I agree. In this case, the nature of the real data allows for this change to make sense, but thank you for your input.</description>
      <pubDate>Tue, 10 Mar 2020 13:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-value-to-0-if-missing-a-way-to-check-for-all-variables/m-p/630905#M186837</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-03-10T13:24:46Z</dc:date>
    </item>
  </channel>
</rss>

