<?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 Using 2 variables with same name from different datasets in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863530#M38151</link>
    <description>&lt;P&gt;I'm trying to run bivar logistic regression on 2 variables but from 2 datasets that have the same var names just from different timepoints. I've listed the code I have so far but essentially, var 2 needs to be from the first dataset and var 1 and 3 need to be from a combination of both datasets.&amp;nbsp;I've tried renaming the variable that needs data from only one data set but when I add the other set, there are fewer values for some reason.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.asdf;&lt;BR /&gt;set 'dataset1'(rename=(var2=var2a));&lt;/P&gt;&lt;P&gt;set 'dataset2';&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I was trying to run:&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt;by var1;&lt;/P&gt;&lt;P&gt;proc freq;&lt;BR /&gt;by var1;&lt;BR /&gt;table var2a*var3 / expected cellchi2 chisq;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2023 20:17:16 GMT</pubDate>
    <dc:creator>beleeve</dc:creator>
    <dc:date>2023-03-10T20:17:16Z</dc:date>
    <item>
      <title>Using 2 variables with same name from different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863530#M38151</link>
      <description>&lt;P&gt;I'm trying to run bivar logistic regression on 2 variables but from 2 datasets that have the same var names just from different timepoints. I've listed the code I have so far but essentially, var 2 needs to be from the first dataset and var 1 and 3 need to be from a combination of both datasets.&amp;nbsp;I've tried renaming the variable that needs data from only one data set but when I add the other set, there are fewer values for some reason.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.asdf;&lt;BR /&gt;set 'dataset1'(rename=(var2=var2a));&lt;/P&gt;&lt;P&gt;set 'dataset2';&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I was trying to run:&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt;by var1;&lt;/P&gt;&lt;P&gt;proc freq;&lt;BR /&gt;by var1;&lt;BR /&gt;table var2a*var3 / expected cellchi2 chisq;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 20:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863530#M38151</guid>
      <dc:creator>beleeve</dc:creator>
      <dc:date>2023-03-10T20:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using 2 variables with same name from different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863536#M38152</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's hard to understand your goal.&amp;nbsp; Can you please show five records of dataset1, five records of dataset2, and what you want to create when you combine them into work.asdf?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are combining variables from dataset1 and dataset2, typically you would do that with a MERGE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are combining rows from dataset1 and dataset2, typically you would do that with a single SET statement which lists both datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your current code, with two SET statements, is almost certainly not doing what you want.&amp;nbsp; But I'm not sure what you're trying to do, so not sure how to help.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 20:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863536#M38152</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-10T20:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using 2 variables with same name from different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863543#M38153</link>
      <description>&lt;P&gt;You might also indicate exactly how you need to use the variable with the same name.&lt;/P&gt;
&lt;P&gt;You can add an variable than indicates which data set a specific record comes from such as&lt;/P&gt;
&lt;PRE&gt;data work.combined;
   set dataset1  (in=in1)
         dataset2  (in=in2)
   ;
   if in1 then Source='Dataset1';
   else if in2 then Source='Dataset2';
run;&lt;/PRE&gt;
&lt;P&gt;You could then use the Source variable in analysis to differentiate between the original set such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc freq data=combined;
   tables source*var2;
run;&lt;/PRE&gt;
&lt;P&gt;Note that multiple SET statements, while allowed by syntax, will get you into some pretty complex behaviors. I suspect that you only have as many records from the larger data set as appeared in the smaller one, especially if dataset1 is the smaller.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 20:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-2-variables-with-same-name-from-different-datasets/m-p/863543#M38153</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-10T20:57:26Z</dc:date>
    </item>
  </channel>
</rss>

