<?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: Way to see where lines are different in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570603#M160924</link>
    <description>You're welcome.</description>
    <pubDate>Tue, 02 Jul 2019 15:33:39 GMT</pubDate>
    <dc:creator>tsap</dc:creator>
    <dc:date>2019-07-02T15:33:39Z</dc:date>
    <item>
      <title>Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570466#M160857</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I agregated a table using proc sql's group by but I see there are a few lines that have duplicate keys. However I have 300 hundreds columns and I can't seem to find the difference manually. Is there a way to see which column are differents between these duplicates?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data have numbers and strings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 09:38:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570466#M160857</guid>
      <dc:creator>emilezola</dc:creator>
      <dc:date>2019-07-02T09:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570467#M160858</link>
      <description>&lt;A href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p0kmnl1zaofxdqn1s5kqz1c1txtu.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p0kmnl1zaofxdqn1s5kqz1c1txtu.htm&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Jul 2019 09:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570467#M160858</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2019-07-02T09:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570524#M160885</link>
      <description>&lt;P&gt;I tried this, but it only seems to be comparing variables between them. I am looking for something that can help me compare the same columns between two rows so I can see which columns are different.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 12:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570524#M160885</guid>
      <dc:creator>emilezola</dc:creator>
      <dc:date>2019-07-02T12:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570562#M160904</link>
      <description>&lt;P&gt;I threw together a dummy table and a macro statement to identify observations that have a duplicate id but a varying value in a different variable. The dummy table only has 6 variables total, but is built to accommodate tables with any number of variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the logic:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.HAVE;
FORMAT 	 ID	$3. Var2 $16. 	Var3 $16. 	Var4 8. 	Var5 $16. 	Var6 $16.;
INFORMAT ID	$3. Var2 $16. 	Var3 $16. 	Var4 8. 	Var5 $16. 	Var6 $16.;
INPUT    ID		VAR2 		VAR3 		VAR4 		VAR5 		VAR6;
INFILE DATALINES DLM='|' DSD;
DATALINES;
123|Red|Blue|100|Yellow|Black
123|Red|Black|100|Yellow|Black
234|Orange|Yellow|80|White|Purple
234|Orange|Yellow|65|White|Purple
345|Yellow|White|90|Green|Brown
456|Green|Brown|25|Red|Orange
;



%MACRO VARIABLEDIFFS(LIBNAME,MEMNAME);
	PROC SQL noprint; 
		select nvar	INTO :TOTALVAR
		from dictionary.tables
		where libname="&amp;amp;LIBNAME."
		and memname="&amp;amp;MEMNAME.";
	QUIT;
	%PUT &amp;amp;=TOTALVAR.;


	proc sql noprint; 
		select name		INTO :Variable1-
		from dictionary.COLUMNS
		where libname="&amp;amp;LIBNAME."
		and memname="&amp;amp;MEMNAME."
		ORDER BY VARNUM; 
	QUIT;

	%DO n=2 %TO &amp;amp;TOTALVAR;
		PROC SQL;
		CREATE TABLE WORK.WANT_&amp;amp;n.	AS
			SELECT DISTINCT a.&amp;amp;Variable1., "&amp;amp;&amp;amp;Variable&amp;amp;n."	AS Diff_Variable
			FROM 		WORK.HAVE	AS a
			INNER JOIN	WORK.HAVE	AS b	ON a.&amp;amp;Variable1.=b.&amp;amp;Variable1.
			WHERE a.&amp;amp;&amp;amp;Variable&amp;amp;n. NE b.&amp;amp;&amp;amp;Variable&amp;amp;n.;
		QUIT;

		PROC APPEND DATA=WORK.WANT_&amp;amp;N.
					BASE=WORK.WANT_ALL;
		RUN; 
		PROC DELETE DATA=WORK.WANT_&amp;amp;N.;
	%END;
%MEND VARIABLEDIFFS;
%VARIABLEDIFFS(WORK,HAVE);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The result in the end, on the table WORK.WANT_ALL is:&lt;/P&gt;&lt;PRE&gt;ID	Diff_Variable&lt;BR /&gt;123	Var3
234	Var4&lt;/PRE&gt;&lt;P&gt;Showing that the observations with ID '123' vary on the variable 'Var3' and ID '234' varies on the variable 'Var4'.&lt;/P&gt;&lt;P&gt;Looking at the dummy data that was loaded for those ids:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For ID '123':&lt;/P&gt;&lt;PRE&gt;123|Red|Blue|100|Yellow|Black &lt;BR /&gt;123|Red|Black|100|Yellow|Black&lt;/PRE&gt;&lt;P&gt;We can confirm that Var3 is different between the two observations. The first observation has 'Blue' for its value of Var3 and the next observation has the value of 'Black'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When calling the macro statement, you include the libname and the table name. In my example it was 'WORK' and 'HAVE'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570562#M160904</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-07-02T13:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570575#M160911</link>
      <description>&lt;P&gt;Thanks for the answer ! I'm having some trouble executing your code. I did create a table named have into my work library with only duplicate data but I'm getting this error :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;WARNING: Variable Diff_Variable has different lengths on BASE and DATA files (BASE 10 DATA 16).
ERROR: No appending done because of anomalies listed above. Use FORCE option to append these files.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I reformat Diff_Variable in this case?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 14:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570575#M160911</guid>
      <dc:creator>emilezola</dc:creator>
      <dc:date>2019-07-02T14:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570584#M160916</link>
      <description>&lt;P&gt;Ahh ok. Yeah I didn't encounter that with the dummy data because all of the variable names being reviewed were the same length.&lt;/P&gt;&lt;P&gt;So what you need to do is set the length of the Diff_Variable to at minimum the value of the longest variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cleaned up the logic a little bit and created a new macro variable that contains the length for the longest variable name to use in the PROC SQL query below it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO VARIABLEDIFFS(LIBNAME,MEMNAME);
	PROC SQL noprint; 
		select nvar					INTO :TOTALVAR		from dictionary.tables	where libname="&amp;amp;LIBNAME."	and memname="&amp;amp;MEMNAME.";
		select name					INTO :Variable1-	from dictionary.COLUMNS	where libname="&amp;amp;LIBNAME."	and memname="&amp;amp;MEMNAME.";
		select MAX(LENGTH(name))	INTO :MaxVarLength	from dictionary.COLUMNS	where libname="&amp;amp;LIBNAME."	and memname="&amp;amp;MEMNAME.";
	QUIT;

	%DO n=2 %TO &amp;amp;TOTALVAR;
		PROC SQL;
		CREATE TABLE WORK.WANT_&amp;amp;n.	AS
			SELECT DISTINCT a.&amp;amp;Variable1., "&amp;amp;&amp;amp;Variable&amp;amp;n."	AS Diff_Variable LENGTH=&amp;amp;MaxVarLength.
			FROM 		WORK.HAVE	AS a
			INNER JOIN	WORK.HAVE	AS b	ON a.&amp;amp;Variable1.=b.&amp;amp;Variable1.
			WHERE a.&amp;amp;&amp;amp;Variable&amp;amp;n. NE b.&amp;amp;&amp;amp;Variable&amp;amp;n.;
		QUIT;

		PROC APPEND BASE=WORK.WANT_ALL
					DATA=WORK.WANT_&amp;amp;N.;
		RUN; 
		PROC DELETE DATA=WORK.WANT_&amp;amp;N.;
	%END;
%MEND VARIABLEDIFFS;
%VARIABLEDIFFS(WORK,HAVE);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 14:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570584#M160916</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-07-02T14:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570586#M160917</link>
      <description>&lt;P&gt;Works just fine ! Thank you very much !&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 14:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570586#M160917</guid>
      <dc:creator>emilezola</dc:creator>
      <dc:date>2019-07-02T14:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Way to see where lines are different</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570603#M160924</link>
      <description>You're welcome.</description>
      <pubDate>Tue, 02 Jul 2019 15:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Way-to-see-where-lines-are-different/m-p/570603#M160924</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-07-02T15:33:39Z</dc:date>
    </item>
  </channel>
</rss>

