<?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: Keeping Mutual Variables In Separate Datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28577#M5263</link>
    <description>Hi all.&lt;BR /&gt;
The solution "transpose-intensive" does not seem to be accurate if your data set is too big (= has too many observations). The first suggestion is more likely to work in any case.&lt;BR /&gt;
The code would look like this...&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC CONTENTS DATA = dataset1 OUT = variables1 NOPRINT ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC CONTENTS DATA = dataset2 OUT = variables2 NOPRINT ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC SQL NOPRINT ;&lt;BR /&gt;
  SELECT first.name INTO : commonVariables SEPARATED BY " "&lt;BR /&gt;
  FROM variables1 AS first,&lt;BR /&gt;
            variables2 AS second&lt;BR /&gt;
  WHERE UPCASE(first.name)=UPCASE(second.name)&lt;BR /&gt;
  ;&lt;BR /&gt;
QUIT ;&lt;BR /&gt;
/* check the variable names */&lt;BR /&gt;
%PUT &amp;amp;commonVariables ;&lt;BR /&gt;
DATA dataset1_common ;&lt;BR /&gt;
  SET dataset1 (KEEP = &amp;amp;commonVariables) ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
DATA dataset2_common ;&lt;BR /&gt;
  SET dataset2 (KEEP = &amp;amp;commonVariables) ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Cheers.&lt;BR /&gt;
Olivier</description>
    <pubDate>Tue, 01 Jul 2008 11:22:18 GMT</pubDate>
    <dc:creator>Olivier</dc:creator>
    <dc:date>2008-07-01T11:22:18Z</dc:date>
    <item>
      <title>Keeping Mutual Variables In Separate Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28574#M5260</link>
      <description>I have what's probably a simple Base SAS question: I have two datasets, with most of the same variables in both sets.  (In other words, 90% of the variables in one set are in the other set.)  I would like to keep only the variables shared by both datasets.  How do I keep the mutual variables, and drop the others from both datasets?</description>
      <pubDate>Mon, 30 Jun 2008 19:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28574#M5260</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-30T19:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Mutual Variables In Separate Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28575#M5261</link>
      <description>i think you can use the "proc contents" to get the variables name of the two datasets. Then chose the mutual variables, and keep them in the two datasets.&lt;BR /&gt;
Not hard to implement by macro.</description>
      <pubDate>Tue, 01 Jul 2008 05:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28575#M5261</guid>
      <dc:creator>Black</dc:creator>
      <dc:date>2008-07-01T05:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Mutual Variables In Separate Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28576#M5262</link>
      <description>It might be a bit tricky.&lt;BR /&gt;
&lt;BR /&gt;
You have say x+y columns in dataset A and x+z columns in dataset B. You want a new dataset C where you have x columns and the data of both A and B.&lt;BR /&gt;
&lt;BR /&gt;
Had it been a row-problem instead of a column problem, it could have been done very easily. Actually that is what I am going to propose.&lt;BR /&gt;
&lt;BR /&gt;
Step 1: Proc Transpose datasets A and B to say A_ and B_, now these have x+y rows (not columns) and x+z rows respectively and if i remember correctly the first variable would be the original column-names (referenced by _NAME_).&lt;BR /&gt;
&lt;BR /&gt;
Step 2: Merge A_ and B_ By _NAME_ (assuming the varaible names in both A and B were same for common variables to start with) when (IN=A_) and (IN=B_), i.e the intersection to get final dataset C_.&lt;BR /&gt;
&lt;BR /&gt;
Step 3: Proc transpose C_ to C so that you get the original format of datasets. You might have to do some data cleaning, formating and renaming of the variables. If you would want to have A and B separate, then you have to insert a new variable to identify from which dataset the column is originally, can do it before step 1 or in step 2 and segregate into A nd B depending on that variable now.</description>
      <pubDate>Tue, 01 Jul 2008 11:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28576#M5262</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-01T11:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Mutual Variables In Separate Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28577#M5263</link>
      <description>Hi all.&lt;BR /&gt;
The solution "transpose-intensive" does not seem to be accurate if your data set is too big (= has too many observations). The first suggestion is more likely to work in any case.&lt;BR /&gt;
The code would look like this...&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC CONTENTS DATA = dataset1 OUT = variables1 NOPRINT ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC CONTENTS DATA = dataset2 OUT = variables2 NOPRINT ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
PROC SQL NOPRINT ;&lt;BR /&gt;
  SELECT first.name INTO : commonVariables SEPARATED BY " "&lt;BR /&gt;
  FROM variables1 AS first,&lt;BR /&gt;
            variables2 AS second&lt;BR /&gt;
  WHERE UPCASE(first.name)=UPCASE(second.name)&lt;BR /&gt;
  ;&lt;BR /&gt;
QUIT ;&lt;BR /&gt;
/* check the variable names */&lt;BR /&gt;
%PUT &amp;amp;commonVariables ;&lt;BR /&gt;
DATA dataset1_common ;&lt;BR /&gt;
  SET dataset1 (KEEP = &amp;amp;commonVariables) ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
DATA dataset2_common ;&lt;BR /&gt;
  SET dataset2 (KEEP = &amp;amp;commonVariables) ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Cheers.&lt;BR /&gt;
Olivier</description>
      <pubDate>Tue, 01 Jul 2008 11:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28577#M5263</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2008-07-01T11:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Mutual Variables In Separate Datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28578#M5264</link>
      <description>Hi:&lt;BR /&gt;
  And to simplify the creation of the macro variable, you could use the DICTIONARY.COLUMNS file in the SQL query:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select a.name &lt;BR /&gt;
     into :commonvariables separated by " "  &lt;BR /&gt;
  from dictionary.columns as a,&lt;BR /&gt;
       dictionary.columns as b  &lt;BR /&gt;
  where upcase(a.name)=upcase(b.name) &lt;BR /&gt;
    and (a.libname="WORK" and a.memname="DATASET1")&lt;BR /&gt;
    and (b.libname="WORK" and b.memname="DATASET2");&lt;BR /&gt;
quit ;&lt;BR /&gt;
          &lt;BR /&gt;
%put commonvariables are = &amp;amp;commonvariables;&lt;BR /&gt;
  &lt;BR /&gt;
** rest of code to create new datasets with the commonvariable macro var.;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 01 Jul 2008 17:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Mutual-Variables-In-Separate-Datasets/m-p/28578#M5264</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-01T17:53:27Z</dc:date>
    </item>
  </channel>
</rss>

