<?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: Creating a table from multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665125#M198810</link>
    <description>&lt;P&gt;Wow.&amp;nbsp; unfortunately that seems much more complicated and beyond my current understanding of SAS.&amp;nbsp; Might there be a different way?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 19:11:15 GMT</pubDate>
    <dc:creator>mcook</dc:creator>
    <dc:date>2020-06-25T19:11:15Z</dc:date>
    <item>
      <title>Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665103#M198795</link>
      <description>&lt;P&gt;I have several tables of just one variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MasterList&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;B&lt;BR /&gt;C&lt;BR /&gt;D&lt;BR /&gt;E&lt;BR /&gt;F&lt;BR /&gt;G&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;E&lt;/P&gt;&lt;P&gt;G&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table3:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var2:&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;C&lt;/P&gt;&lt;P&gt;E&lt;/P&gt;&lt;P&gt;F&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with the rest similar.&amp;nbsp; With each table having some or all of the values in MasterList.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to create a table with the variables (var1, var2, etc) as the observations, and the columns A, B,....,G from MasterList.&lt;/P&gt;&lt;P&gt;where the observation has a value of 1 if it contains that element from MasterList, and 0 if it does not.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like so.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp;D&amp;nbsp; &amp;nbsp;E&amp;nbsp; &amp;nbsp;F&amp;nbsp; &amp;nbsp;G&lt;/P&gt;&lt;P&gt;Var1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Var2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;Var3&amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 17:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665103#M198795</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2020-06-25T17:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665121#M198808</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;maybe like this (a view, format, tabulate, and a text file &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
input MasterList $;
cards;
A
B
C
D
E
F
G
;
run;

data Table2;
input Var1 $;
cards;
A
B
E
G
;
run;
 

data Table3;
input Var2 $;
cards;
B
C
E
F
;
run;

data TMP/view = TMP;
  merge table:;
  array _X_(i) _character_;

  do over _X_;
    _name_ = vname(_X_);
    _value_ = _X_;
    output;
  end;
  keep _name_ _value_;
run;

proc format;
  value bool
  0,. = 0
  other = 1
  ;
run;

data _null_;
  set table1 end = eof;
  length list $ 1000;
  retain list;
  list = catx(" ", list, MasterList);
  if eof;
  call symputx("list", list, "G");
run;

ods _all_ close;
options ps = max ls = max nocenter nodate nonumber formchar="";
title;
filename f TEMP;
proc printto print = f;
run;
proc tabulate data = TMP;
  class _name_ _value_;
  table _name_=" ", _value_=" "*n=" "*f=bool.;
run;
proc printto;
run;
ods html;

data want;
  infile f firstobs = 6;
  input @@;
  put _infile_;
  if _infile_ ne "" then
    do;
      input var_name : $ 32. &amp;amp;list.;
      output;
    end;
  else input;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 19:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665121#M198808</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-25T19:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665125#M198810</link>
      <description>&lt;P&gt;Wow.&amp;nbsp; unfortunately that seems much more complicated and beyond my current understanding of SAS.&amp;nbsp; Might there be a different way?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 19:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665125#M198810</guid>
      <dc:creator>mcook</dc:creator>
      <dc:date>2020-06-25T19:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665139#M198819</link>
      <description>&lt;P&gt;You can use next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MasterList;
  infile cards;
  input key $;
cards;
A                                    
B
C
D
E
F
G
; run;

data table2;
  infile cards;
  input key $;
cards;
A                                    
B
E
G
; run;

data table3;
  infile cards;
  input key $;
cards;
B                                    
C
E
F
; run;

%macro assign;
   select (key);
    when ('A')  i=1;
	when ('B')  i=2;
    when ('C')  i=3;
	when ('D')  i=4;
    when ('E')  i=5;
	when ('F')  i=6;
	when ('G')  i=7;
	otherwise put '***Error ' key=;
   end;
   x(i) = 1;
%mend assign;

proc sql noprint;
  select key into :list1 separated by ' '
  from MasterList
  ;
  select key into :list2 separated by ','
  from MasterList
  ;
quit;

data want;
     retain &amp;amp;list1;
     drop i key;
     
     array x {*} &amp;amp;list1;
	 do i=1 to dim(x); x(i)=0; end;

  /* any non last table */	 
	 do until (eof);
	    set table2 end=eof;
		   %assign;
		   if eof then output;
	 end;
	 do i=1 to dim(x); x(i)=0; end; eof=0;

  /* last table */	 
	 do until (eof);
	    set table3 end=eof;
		   %assign;
		   if eof then output;
	 end;
	 
run;
	 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 19:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665139#M198819</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-25T19:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665141#M198820</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TMP/view = TMP;
  merge table:;
  array _X_(i) _character_;

  do over _X_;
    _nm_ = vname(_X_);
    _value_ = _X_;
    output;
  end;
  keep _nm_ _value_;
run;

proc tabulate data = TMP out = o(keep = _nm_ _value_ N);
  class _nm_ _value_;
  table _nm_=" ", _value_=" "*n=" ";
run;

proc transpose data = o out = want(drop = _name_);
  by _nm_;
  var N;
  id _value_;
run;

data want;
  set want;
  array N _numeric_;
  do over N;
    N = (N &amp;gt; .);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 19:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665141#M198820</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-25T19:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665147#M198824</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
input MasterList $;
cards;
A
B
C
D
E
F
G
;
run;

data Table2;
input Var1 $;
cards;
A
B
E
G
;
run;

data Table3;
input Var2 $;
cards;
B
C
E
F
;
run;

data _null_;
	length vlst $25.;
	set Table1 end=done;
	retain vlst ' ';
	vlst=catx(' ',vlst,MasterList);
	put _all_;

	if done then
		call symputx('vlst',vlst);
run;

%put &amp;amp;vlst.;

data Test;
	array mlist[*] &amp;amp;vlst.;
	set Table2 Table3(rename=(var2=var1)) indsname=dsname;

	do i=1 to dim(mlist);
		if vname(mlist[i])=var1 then
			mlist[i]=1;
		else mlist[i]=0;
	end;

	varname=transtrn(scan(dsname,2),'TABLE','VAR');
	Drop i Var1;
run;

proc means data=test nway missing noprint;
	class varname;
	var &amp;amp;vlst.;
	output out= want(drop=_:) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 20:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665147#M198824</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-06-25T20:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665150#M198827</link>
      <description>&lt;P&gt;Alternatively and simplified code will be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select key into :list1 separated by ' '
  from MasterList
  ;
quit;

data want;
     retain &amp;amp;list1;
     cx = compress("&amp;amp;list1");
     drop i key cx;
     
     array x {*} &amp;amp;list1;
	 do i=1 to dim(x); x(i)=0; end;

  /* any non last table */	 
	 do until (eof);
	    set table2 end=eof;
		   i = indexc(cx,key);
		   x(i) = 1;
		   if eof then output;
	 end;
	 do i=1 to dim(x); x(i)=0; end; eof=0;

  /* last table */	 
	 do until (eof);
	    set table3 end=eof;
		   i = indexc(cx,key);
		   x(i) = 1;
		   if eof then output;
	 end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 20:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665150#M198827</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-25T20:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a table from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665343#M198930</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Table1;
input MasterList $;
cards;
A
B
C
D
E
F
G
;
run;

data Table2;
input Var1 $;
cards;
A
B
E
G
;
run;

data Table3;
input Var2 $;
cards;
B
C
E
F
;
run;

%macro tran(dsn=,var=);
data temp;
 set &amp;amp;dsn;
 _&amp;amp;var=1;
run;
proc transpose data=temp  out=_&amp;amp;dsn;
id &amp;amp;var;
var _&amp;amp;var;
run;
%mend;

%tran(dsn=table1,var=MasterList)
%tran(dsn=table2,var=var1)
%tran(dsn=table3,var=var2)

data all;
 set _: ;
run;
proc stdize data=all out=want reponly missing=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2020 13:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-from-multiple-tables/m-p/665343#M198930</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-26T13:02:27Z</dc:date>
    </item>
  </channel>
</rss>

