<?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 Proc compare - replacing missing as 100 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/559303#M156164</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have two datasets and i need to get variance between two dataset so i have used proc compare. I need missing values in the output to be changed to 100 in my output when either one of the input has a value and other one has zero or missing. The data i have mentioned here is sample one. Rows and columns will be more in actual data.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**Dataset 1**/

Data DT1;
input v_id $ @4 month1 @7 month2 @10 month3;
datalines;
aa 12 58 0 
bb 34 47 . 
cc 25 .  54
;
run;

/**Dataset 2**/

Data DT2;
input v_id $ @4 month1 @7 month2 @10 month3;
datalines;
aa 62 58 3 
bb 34 47 . 
cc 15 0  54
dd 15 12 14
ee 8  9  65
;
run;

/** Compare***/

Proc compare base=dt1
compare=dt2 OUTPERCENT
out=result noprint;
ID V_Id;
VAR _NUMERIC_;
run;

/**Output from proc compare**/
_TYPE_	_OBS_	v_id	month1	month2	month3
PERCENT	1	aa	416.6666667	0	.
PERCENT	2	bb	0	0	.
PERCENT	3	cc	-40	.	0

/**expected output**/

_TYPE_	_OBS_	v_id	month1	month2	month3
PERCENT	1	aa	416.6666667	0	100
PERCENT	2	bb	0	0	.
PERCENT	3	cc	-40	.	0


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 13:31:35 GMT</pubDate>
    <dc:creator>SAS_prep</dc:creator>
    <dc:date>2019-05-16T13:31:35Z</dc:date>
    <item>
      <title>Proc compare - replacing missing as 100</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/559303#M156164</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have two datasets and i need to get variance between two dataset so i have used proc compare. I need missing values in the output to be changed to 100 in my output when either one of the input has a value and other one has zero or missing. The data i have mentioned here is sample one. Rows and columns will be more in actual data.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**Dataset 1**/

Data DT1;
input v_id $ @4 month1 @7 month2 @10 month3;
datalines;
aa 12 58 0 
bb 34 47 . 
cc 25 .  54
;
run;

/**Dataset 2**/

Data DT2;
input v_id $ @4 month1 @7 month2 @10 month3;
datalines;
aa 62 58 3 
bb 34 47 . 
cc 15 0  54
dd 15 12 14
ee 8  9  65
;
run;

/** Compare***/

Proc compare base=dt1
compare=dt2 OUTPERCENT
out=result noprint;
ID V_Id;
VAR _NUMERIC_;
run;

/**Output from proc compare**/
_TYPE_	_OBS_	v_id	month1	month2	month3
PERCENT	1	aa	416.6666667	0	.
PERCENT	2	bb	0	0	.
PERCENT	3	cc	-40	.	0

/**expected output**/

_TYPE_	_OBS_	v_id	month1	month2	month3
PERCENT	1	aa	416.6666667	0	100
PERCENT	2	bb	0	0	.
PERCENT	3	cc	-40	.	0


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 13:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/559303#M156164</guid>
      <dc:creator>SAS_prep</dc:creator>
      <dc:date>2019-05-16T13:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc compare - replacing missing as 100</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/559309#M156165</link>
      <description>&lt;P&gt;Hope the below code will help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data DT1;
input v_id $ @4 month1 @7 month2 @10 month3;
datalines;
aa 12 58 0 
bb 34 47 . 
cc 25 .  54
;
run;

/**Dataset 2**/

Data DT2;
input v_id $ @4 month1 @7 month2 @10 month3;
datalines;
aa 62 58 3 
bb 34 47 . 
cc 15 0  54
dd 15 12 14
ee 8  9  65
;
run;


data all;
merge DT1(in=a) DT2(in=b rename=(month1=_month1 month2=_month2 month3=_month3));
by v_id;
run;

data want;
set all;
array var1(*) month1 month2 month3;
array var2(*) _month1 _month2 _month3;
do i = 1 to dim(var1);
if var1(i)=0 then var1(i)=.;
if var2(i)=0 then var2(i)=.;
if nmiss(var1(i),var2(i))=1 then do; var1(i)=coalesce(var1(i),100); var2(i)=coalesce(var2(i),100); end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 May 2019 13:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/559309#M156165</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-16T13:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc compare - replacing missing as 100</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/560167#M156560</link>
      <description>&lt;P&gt;Hi jag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i am not getting the right result. The value v_id for month3 in DT1 is 0 and in DT2 it is 3. for this combination my output should have 100 as variance.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 14:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-compare-replacing-missing-as-100/m-p/560167#M156560</guid>
      <dc:creator>SAS_prep</dc:creator>
      <dc:date>2019-05-20T14:53:11Z</dc:date>
    </item>
  </channel>
</rss>

