<?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: How to use variables with same name but different datasets in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860319#M38013</link>
    <description>&lt;P&gt;Another approach is to combine the two sets into a single data set and add a variable that indicates the name of the data set that contributes which records. Then use that added variable to indicate the source in analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data combined;
   set data1 data2 indsname=source;
   table_name=source;
run;

proc freq data=combined;
    tables  table_name* (var1 var2);
run;&lt;/PRE&gt;
&lt;P&gt;Combining the data will require that all variables with the same name be of the same type and best to have the same length.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2023 23:44:35 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-02-22T23:44:35Z</dc:date>
    <item>
      <title>How to use variables with same name but different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860304#M38010</link>
      <description>&lt;P&gt;I uploaded 2 datasets from different timepoints but they use the same variable names. Is there a way I can perform proc freq on a variable from dataset 1 and the variable from dataset 2 specifically even though the variables use the same names in both?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 20:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860304#M38010</guid>
      <dc:creator>beleeve</dc:creator>
      <dc:date>2023-02-22T20:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use variables with same name but different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860306#M38011</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data  = Mydata1;
  table MyVar;
run;

proc freq data  = Mydata2;
  table MyVar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 21:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860306#M38011</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-22T21:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use variables with same name but different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860319#M38013</link>
      <description>&lt;P&gt;Another approach is to combine the two sets into a single data set and add a variable that indicates the name of the data set that contributes which records. Then use that added variable to indicate the source in analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data combined;
   set data1 data2 indsname=source;
   table_name=source;
run;

proc freq data=combined;
    tables  table_name* (var1 var2);
run;&lt;/PRE&gt;
&lt;P&gt;Combining the data will require that all variables with the same name be of the same type and best to have the same length.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 23:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860319#M38013</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-22T23:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use variables with same name but different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860374#M38015</link>
      <description>&lt;P&gt;To minimize disk space consumption, I would use a view in &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;'s code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combined / view=combined;
   set data1 data2 indsname=source;
   table_name=source;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which means that the append is done dynamically when the view is used in PROC FREQ later.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 07:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/860374#M38015</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-23T07:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use variables with same name but different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/863519#M38150</link>
      <description>&lt;P&gt;Sorry I forgot to mention that the other variable is from only one of the data sets. Right now I have something like this where var 1 and var2 is from both datasets and var 3 is only from data1:&lt;/P&gt;&lt;P&gt;data work.abc;&lt;BR /&gt;set 'data1.sas7bdat';&lt;BR /&gt;set 'data2.sas7bdat';&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 var2*var3/ expected cellchi2 chisq;&lt;BR /&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 18:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/863519#M38150</guid>
      <dc:creator>beleeve</dc:creator>
      <dc:date>2023-03-10T18:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use variables with same name but different datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/863594#M38154</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439435"&gt;@beleeve&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry I forgot to mention that the other variable is from only one of the data sets. Right now I have something like this where var 1 and var2 is from both datasets and var 3 is only from data1:&lt;/P&gt;
&lt;P&gt;data work.abc;&lt;BR /&gt;set 'data1.sas7bdat';&lt;BR /&gt;set 'data2.sas7bdat';&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 var2*var3/ expected cellchi2 chisq;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is past time that you learned to use libraries, such as WORK instead of file literal names like&amp;nbsp; 'data1.sas7bdat' That just adds to complexity of code.&lt;/P&gt;
&lt;P&gt;Second, TWO SET STATEMENTS behave differently than you expect, which is why you lose records.&lt;/P&gt;
&lt;P&gt;If you want to do something like that Chisq how do you know that the var2 and var3 are the right combination of observations from your source sets? For chi-square to be meaningful the values have to be matched some way and your double set statements are almost certainly not doing anything sensible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SHOW example data sets as data step code. Or output proc print of the relevant variables from each set to the LISTING&amp;nbsp; destination and paste the result into a TEXT opened on the forum with the &amp;lt;/&amp;gt; icon above the message window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Mar 2023 12:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-variables-with-same-name-but-different-datasets/m-p/863594#M38154</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-11T12:13:29Z</dc:date>
    </item>
  </channel>
</rss>

