<?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: Appending datasets and identifying missing variables in the output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945592#M370446</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used a set statement only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution I've found is using arrays.&lt;/P&gt;
&lt;P&gt;I'm just assuming that there is a better way of doing it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This can not result in what you posted.&lt;/P&gt;
&lt;P&gt;Code I ran on SAS ODA:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    a='A';
    b='B';
    x=1;
    y=1;
run;

data b;
    a='A';
    c='C';
    x=2;
    z=2;
run;

data want;
set a b;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Beob.	a	b	x	y	c	z
1	A	B	1	1	 	.
2	A	 	2	.	C	2
&lt;/PRE&gt;
&lt;P&gt;As you can see, the order of the variables is different, and the display of the missing values is as it should be.&lt;/P&gt;
&lt;P&gt;So you must have run different code, and additional things (e.g. formats assigned to the variables, or a custom setting of OPTIONS MISSING.&lt;/P&gt;
&lt;P&gt;As already said, &lt;STRONG&gt;POST YOUR COMPLETE CODE&lt;/STRONG&gt;, and add the result of PROC CONTENTS from your result dataset, and the setting of the MISSING option.&lt;/P&gt;</description>
    <pubDate>Sun, 29 Sep 2024 11:04:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-09-29T11:04:56Z</dc:date>
    <item>
      <title>Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945565#M370441</link>
      <description>&lt;P&gt;Datasets to append can have different variables.&lt;/P&gt;
&lt;P&gt;Sometimes, it can be useful to identify in the output dataset when values are missing before the variable was not in the original dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    a='A';
    b='B';
    x=1;
    y=1;
run;

data b;
    a='A';
    c='C';
    x=2;
    z=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How would you get a slash when the character variable was missing and a .A when the numeric variable was missing?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xxformat_com_0-1727582653828.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100732i1A7015075F4E5418/image-size/medium?v=v2&amp;amp;px=400" role="button" title="xxformat_com_0-1727582653828.png" alt="xxformat_com_0-1727582653828.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2024 04:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945565#M370441</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2024-09-29T04:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945573#M370442</link>
      <description>Please show the code you used to append the datasets.</description>
      <pubDate>Sun, 29 Sep 2024 06:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945573#M370442</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-09-29T06:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945584#M370444</link>
      <description>&lt;P&gt;I used a set statement only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution I've found is using arrays.&lt;/P&gt;
&lt;P&gt;I'm just assuming that there is a better way of doing it.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2024 09:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945584#M370444</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2024-09-29T09:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945592#M370446</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used a set statement only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution I've found is using arrays.&lt;/P&gt;
&lt;P&gt;I'm just assuming that there is a better way of doing it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This can not result in what you posted.&lt;/P&gt;
&lt;P&gt;Code I ran on SAS ODA:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    a='A';
    b='B';
    x=1;
    y=1;
run;

data b;
    a='A';
    c='C';
    x=2;
    z=2;
run;

data want;
set a b;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Beob.	a	b	x	y	c	z
1	A	B	1	1	 	.
2	A	 	2	.	C	2
&lt;/PRE&gt;
&lt;P&gt;As you can see, the order of the variables is different, and the display of the missing values is as it should be.&lt;/P&gt;
&lt;P&gt;So you must have run different code, and additional things (e.g. formats assigned to the variables, or a custom setting of OPTIONS MISSING.&lt;/P&gt;
&lt;P&gt;As already said, &lt;STRONG&gt;POST YOUR COMPLETE CODE&lt;/STRONG&gt;, and add the result of PROC CONTENTS from your result dataset, and the setting of the MISSING option.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2024 11:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945592#M370446</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-09-29T11:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945594#M370448</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184742"&gt;@xxformat_com&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used a set statement only.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show us the code.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2024 12:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945594#M370448</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-29T12:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945602#M370449</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    a='A';
    b='B';
    x=1;
    y=1;
run;

data b;
    a='A';
    c='C';
    x=2;
    z=2;
run;

data z (drop=i j);
    set a b;
    array charvar {*} _character_; 
    array numvar  {*} _numeric_;
    do i=1 to dim(charvar);
        if charvar{i} = ' ' then charvar{i}='/';
    end;
    do j=1 to dim(numvar);
        if numvar{j} = . then numvar{j}=.A;
    end;
run;

proc print data=z;
   var a b c x y z;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I'm assuming there is an easier approach.&lt;/P&gt;
&lt;P&gt;Actually, I added more data and an extra layer of difficulty after that in my code because any missing value of an existing variable should not be reported with / or .A&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    a='A';
    b='B';
    w=.;
    x=1;
    y=1;
run;

data b;
    a='A';
    c='C';
    d=' ';
    x=2;
    z=2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At the end, my excel report changes the background of the cells only when the variables were not in the original datasets (my datasets are coming from .csv file I import) and I have an extra layer of probably unneeded complication using a loop for call define in proc report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2024 15:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945602#M370449</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2024-09-29T15:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945603#M370450</link>
      <description>&lt;P&gt;This program preserves original missing values in A and B, but gives the new designated "missing" values&amp;nbsp; when the variable lists are expanded to include all vars not originally in both datasets.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data notina(drop=_left--_right);
  retain _Left .;
  set a (obs=1);
  retain _Right ' ';
  set b;
  array _n _numeric_;
  array _c _character_;
  do over _n;  _n=.A;  end;
  do over _c;  _c='/'; end;
run;
data notinb(drop=_left--_right);
  retain _Left .;
  set b (obs=1);
  retain _Right ' ';
  set a;
  array _n _numeric_;
  array _c _character_;
  do over _n;  _n=.A;  end;
  do over _c;  _c='/'; end;
run;

data want;
  set a (in=ina)  b  (in=inb);
  retain _p 1;
  if ina then set notina point=_p;
  if inb then set notinb point=_p;
run;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Sep 2024 15:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945603#M370450</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-09-29T15:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945612#M370452</link>
      <description>&lt;P&gt;Set all of the variables to your special values BEFORE the SET.&amp;nbsp; That way the values read will overwrite the special values.&amp;nbsp; Use IF 0 THEN (an obviously false condition) to allow the data step compiler to see all the datasets so all of the variables are define so the ARRAY statement can find them.&lt;/P&gt;
&lt;P&gt;But you need to use a separate SET statement for each dataset. Otherwise the SET operation will clear (set to missing) the variables that do not come from that particular dataset.&amp;nbsp; When setting each dataset separately the SET statement will not do that since its won't know anything about the other dataset(s) that are not mentioned.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input a $ b $ x y ;
cards;
A1 B1 1 1
A2 . 3 .
;

data b;
  input a $ c $ x z ;
cards;
A3 C1 2 2
. C2 . 4 
;

data want;
  if 0 then set a b ;
  array _char_ _character_;
  array _num_ _numeric_;
  do over _char_ ;
    _char_='/';
  end;
  do over _num_;
    _num_=.A;
  end;
  if not eof then set a end=eof;
  else set b ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    a     b     x    y    c     z

 1     A1    B1    1    1    /     A
 2     A2          3    .    /     A
 3     A3    /     2    A    C1    2
 4           /     .    A    C2    4

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 01:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945612#M370452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-30T01:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Appending datasets and identifying missing variables in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945615#M370453</link>
      <description>&lt;P&gt;If this is just about display/print then a format could do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  a='A';
  b='B';
  w=.;
  x=1;
  y=1;
  v=.;
run;

data b;
  a='A';
  c='C';
  d=' ';
  x=2;
  z=2;
  v=.;
run;

proc format;
  value numMiss
    . = .A
    ;
  value $charMiss
    ' ' = '/'
    ;
run;

data all;
  set a b;
  format _character_ $charMiss. _numeric_ numMiss.;
run;

proc print data=all;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1727659652637.png" style="width: 339px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100753iDFE613BD4304D545/image-dimensions/339x102?v=v2" width="339" height="102" role="button" title="Patrick_1-1727659652637.png" alt="Patrick_1-1727659652637.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I've added a variable V to your sample data to demonstrate that a missing doesn't tell you if a source variable existed in both source tables or not. It can just be missing in both source tables.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 01:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-datasets-and-identifying-missing-variables-in-the/m-p/945615#M370453</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-09-30T01:28:59Z</dc:date>
    </item>
  </channel>
</rss>

