<?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: Compare the order of variables (not their values) in different datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446212#M111921</link>
    <description>&lt;P&gt;Maxim 1: Read the documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148439.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148439.htm&lt;/A&gt;&amp;nbsp;contains a fine example for the usage of varnum().&lt;/P&gt;</description>
    <pubDate>Fri, 16 Mar 2018 15:20:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-16T15:20:54Z</dc:date>
    <item>
      <title>Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446164#M111891</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm working to compare two Excel files after importing them both in SAS.&amp;nbsp; I need to track column name changes...if the order of the column names changes, I need to know.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first Excel file has 50 columns and is a current 2018 version.&amp;nbsp; The column names are EmpID, Date, Gender, Pay, Dept., etc, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second Excel file has 50 columns, but is an archived 2017 version.&amp;nbsp; The column names are the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if the order of the column names (variables) change in 2018, then I want to know.&amp;nbsp; So, if instead the 2018 Excel file column name changes to EmpID, Gender, Pay, Date, etc. etc (the "Date" column moves from 2nd position, to 4th position), which is different from 2017... I want SAS to let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the proc compare, but proc compare doesn't track position changes with variable names.&amp;nbsp; I can't find a solution to this anywhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help is much appreciated...and thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 13:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446164#M111891</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-03-16T13:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446169#M111895</link>
      <description>&lt;P&gt;Look at varnum in dictionary.columns (proc sql).&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 14:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446169#M111895</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-16T14:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446171#M111896</link>
      <description>&lt;P&gt;Assume Two set of variables are compared. What is the output you want?. Show it by example.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 14:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446171#M111896</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-03-16T14:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446179#M111900</link>
      <description>&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;2018 file = EmpID, Gender, Pay, Dept.,&amp;nbsp;Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2017 file = EmpID, Date, Gender, Pay, Dept.,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output would something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error - column 2 or "Date" is not in 2nd position in 2018.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error - column 2 is out of order from 2017 archive.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 14:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446179#M111900</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-03-16T14:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446201#M111914</link>
      <description>&lt;P&gt;I used this code as a test... but it failed.&amp;nbsp; Pls help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set work.ACH;&lt;/P&gt;&lt;P&gt;check = varnum("work.ach","EmpID");&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought it would give me the result of check = 1 ; which is the position of EmpID.&amp;nbsp; What am I missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My log:&lt;/P&gt;&lt;P&gt;26:17&lt;BR /&gt;NOTE: Invalid numeric data, 'work.ach' , at line 26 column 17.&lt;BR /&gt;NOTE: Argument 1 to function VARNUM(.,'EmpID') at line 26 column 10 is invalid.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 15:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446201#M111914</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-03-16T15:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446202#M111915</link>
      <description>&lt;P&gt;Here is one&amp;nbsp;way to&amp;nbsp;approach this with two very small data sets as a concrete example. We don't need lots of values for this exercise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.junk1;
   input x y z;
datalines ;
1 2 3
;

data work.junk2;
   input x z $ y$ a;
datalines;
2 3 4 5
;
run;

proc sql;
   create table varcompare as
   select memname, name, varnum, type
   from dictionary.columns
   where libname='WORK' and memname in ('JUNK1' 'JUNK2')
   ;
run;

proc tabulate data=varcompare;
   class memname name varnum type;
   tables name*varnum ,
          memname=''*type=''*n=''
          /misstext=' '
          ;
run;
&lt;/PRE&gt;
&lt;P&gt;Note that I included the variable type, numeric or character, as well since different spreadsheets are notorious for resulting in different variable types for similar names. I also include a variable that only occurs in one set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The proc tabulate output shows a 1 for the values observed. So in this output you can see that variable A only exists in JUNK2, the variables Y and Z appear in different columns and which columns are involved AND that Y and Z both changed variable types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would also allow incorporating more datasets in the analysis that are supposed to be similar by including the names in the where clause in the proc sql. The syntax for that where might cumbersome if you have to look at multiple libraries. The Libname and Memname values in the dictionary.columns are stored in all uppercase so that is what should be on the where clause.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 15:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446202#M111915</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-16T15:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446212#M111921</link>
      <description>&lt;P&gt;Maxim 1: Read the documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148439.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148439.htm&lt;/A&gt;&amp;nbsp;contains a fine example for the usage of varnum().&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 15:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446212#M111921</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-16T15:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446242#M111933</link>
      <description>great.</description>
      <pubDate>Fri, 16 Mar 2018 16:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446242#M111933</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-03-16T16:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446244#M111934</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;this gives me a start - thanks for taking the time to provide a clear example.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 16:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446244#M111934</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-03-16T16:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the order of variables (not their values) in different datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446257#M111945</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/92272"&gt;@belboy&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;this gives me a start - thanks for taking the time to provide a clear example.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have a program that does something similar for 20 data sets with changing content (a government sponsored survey and so the content WILL change so don't blame me) where I used this approach to examine variable labels because we had "same label different variable) and "same variable different label". Also as a reference for which yearly set to look for related topics. Then I could be prepared for some of the things likely to watch for when combining data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the nice things I like about SAS is, assuming matching variable name and types, combining data sets does not depend on the order of variables within sets.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 16:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-order-of-variables-not-their-values-in-different/m-p/446257#M111945</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-16T16:55:20Z</dc:date>
    </item>
  </channel>
</rss>

