<?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 Checking if a record is in another table, and making it empty if it isn't in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738069#M230165</link>
    <description>&lt;P&gt;I am trying to set up a data step that expunges some 'incorrect' values from a dataset. For instance, I have a table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;a;&lt;/P&gt;&lt;P&gt;input (A1 A2 A3)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp; B&amp;nbsp; D&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp; B&amp;nbsp; D&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;D&amp;nbsp; A&amp;nbsp; E&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I am trying to remake the table but where all values are within this column/dataset (only A, B and C):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;b&lt;/SPAN&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;input (B1)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;C&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Such that the final output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;a_2;&lt;/P&gt;&lt;P&gt;input (A1 A2 A3)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp; B&amp;nbsp; &lt;/FONT&gt;&lt;FONT color="#333333"&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp; B&amp;nbsp;&lt;FONT color="#333333"&gt; .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#333333"&gt;.&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;A&amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can check if a variable is 'in' a column with PROC SQL, but it seems like the code to do so would be a bit long - my actual dataset involves far more than 3 variables and 3 allowed values so I was curious if there was a simpler way to do it.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Apr 2021 01:55:43 GMT</pubDate>
    <dc:creator>DAppelbaum83</dc:creator>
    <dc:date>2021-04-30T01:55:43Z</dc:date>
    <item>
      <title>Checking if a record is in another table, and making it empty if it isn't</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738069#M230165</link>
      <description>&lt;P&gt;I am trying to set up a data step that expunges some 'incorrect' values from a dataset. For instance, I have a table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;a;&lt;/P&gt;&lt;P&gt;input (A1 A2 A3)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp; B&amp;nbsp; D&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp; B&amp;nbsp; D&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;D&amp;nbsp; A&amp;nbsp; E&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I am trying to remake the table but where all values are within this column/dataset (only A, B and C):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;b&lt;/SPAN&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;input (B1)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;C&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Such that the final output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;a_2;&lt;/P&gt;&lt;P&gt;input (A1 A2 A3)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp; B&amp;nbsp; &lt;/FONT&gt;&lt;FONT color="#333333"&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp; B&amp;nbsp;&lt;FONT color="#333333"&gt; .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#333333"&gt;.&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;A&amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can check if a variable is 'in' a column with PROC SQL, but it seems like the code to do so would be a bit long - my actual dataset involves far more than 3 variables and 3 allowed values so I was curious if there was a simpler way to do it.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 01:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738069#M230165</guid>
      <dc:creator>DAppelbaum83</dc:creator>
      <dc:date>2021-04-30T01:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a record is in another table, and making it empty if it isn't</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738079#M230171</link>
      <description>&lt;P&gt;Create a custom format that will map each variable back to its value if it's in your list and to . otherwise.&amp;nbsp;&lt;BR /&gt;You can then apply it to all variables with an array or format statement as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are your variables character, numeric or a mixture?&lt;/P&gt;
&lt;P&gt;You've shown character variables but are using the period, which is typically used to represent only numeric missing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/379698"&gt;@DAppelbaum83&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to set up a data step that expunges some 'incorrect' values from a dataset. For instance, I have a table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;a;&lt;/P&gt;
&lt;P&gt;input (A1 A2 A3)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp; B&amp;nbsp; D&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp; B&amp;nbsp; D&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;D&amp;nbsp; A&amp;nbsp; E&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I am trying to remake the table but where all values are within this column/dataset (only A, B and C):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;b&lt;/SPAN&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;input (B1)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;C&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such that the final output is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;data&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;a_2;&lt;/P&gt;
&lt;P&gt;input (A1 A2 A3)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#666699"&gt;($)&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080"&gt;datalines;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;A&amp;nbsp; B&amp;nbsp; &lt;/FONT&gt;&lt;FONT color="#333333"&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;B&amp;nbsp; B&amp;nbsp;&lt;FONT color="#333333"&gt; .&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#333333"&gt;.&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;A&amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I can check if a variable is 'in' a column with PROC SQL, but it seems like the code to do so would be a bit long - my actual dataset involves far more than 3 variables and 3 allowed values so I was curious if there was a simpler way to do it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 02:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738079#M230171</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-30T02:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a record is in another table, and making it empty if it isn't</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738080#M230172</link>
      <description>&lt;P&gt;They're all categorical / characters. What do you mean custom format? Is there a PROC for that?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 02:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738080#M230172</guid>
      <dc:creator>DAppelbaum83</dc:creator>
      <dc:date>2021-04-30T02:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a record is in another table, and making it empty if it isn't</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738081#M230173</link>
      <description>&lt;P&gt;Categorical doesn't mean character, so assuming all are characters something like this will work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create a format from the data set B;
data b_format;
	set b end=last;
	fmtname="$miss_fmt";
	start=B1;
	label="$8.";
	*tells SAS the format is the label type;
	HLO="F";
	output;

	if last then
		do;
			HLO='O';
			start="**OTHER**";
			label="";
			output;
		end;
run;

proc format cntlin=b_format;
run;

*apply the format to data;
proc print data=a;
	format _character_ $miss_fmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/379698"&gt;@DAppelbaum83&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;They're all categorical / characters. What do you mean custom format? Is there a PROC for that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you're not familiar with User Defined Formats, versus custom formats this is a good start.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf" target="_blank"&gt;PDF 001-30: PROC FORMAT - Not Just Another Pretty Face&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 02:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738081#M230173</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-30T02:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a record is in another table, and making it empty if it isn't</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738082#M230174</link>
      <description>&lt;P&gt;Yes, PROC FORMAT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $lookup
  'A', 'B', 'C' = 'Y'
  other = 'N'
 ;
run;

data want;
  set have;
  if put(A1, $lookup.) = 'N' then A1 = '';
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Apr 2021 02:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738082#M230174</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-30T02:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if a record is in another table, and making it empty if it isn't</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738151#M230199</link>
      <description>&lt;PRE&gt; 

data a;
input (A1 A2 A3) ($);
datalines;
A  B  D
B  B  D
D  A  E
;

 


 

data b;
input (B1) ($);
datalines;
A  
B  
C 
;

data want;
 if _n_=1 then do;
  if 0 then set b;
  declare hash h(dataset:'b');
  h.definekey('B1');
  h.definedone();
 end;
set a;
array x{*} a: ;
do i=1 to dim(x);
 if h.check(key:x{i}) ne 0 then call missing(x{i});
end;
drop i b1;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Apr 2021 13:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-if-a-record-is-in-another-table-and-making-it-empty-if/m-p/738151#M230199</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-30T13:14:55Z</dc:date>
    </item>
  </channel>
</rss>

