<?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 count of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694247#M211712</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have sas access to hadoop.&lt;/P&gt;
&lt;P&gt;In one of the database i have around 300 hive tables. I need to find the number of columns from each table. for e.g., something like this&lt;/P&gt;
&lt;P&gt;Table_name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v_count&lt;/P&gt;
&lt;P&gt;Account_Stat_8&amp;nbsp;&amp;nbsp;&amp;nbsp; 36&lt;/P&gt;
&lt;P&gt;Accoutn_Stat_9&amp;nbsp;&amp;nbsp;&amp;nbsp; 36&lt;/P&gt;
&lt;P&gt;Customer_det&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically i am trying to find the number columns from Hive tables using SAS.&lt;/P&gt;
&lt;P&gt;Could someone help me with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;vnreddy&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2020 14:18:22 GMT</pubDate>
    <dc:creator>vnreddy</dc:creator>
    <dc:date>2020-10-26T14:18:22Z</dc:date>
    <item>
      <title>count of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694247#M211712</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have sas access to hadoop.&lt;/P&gt;
&lt;P&gt;In one of the database i have around 300 hive tables. I need to find the number of columns from each table. for e.g., something like this&lt;/P&gt;
&lt;P&gt;Table_name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v_count&lt;/P&gt;
&lt;P&gt;Account_Stat_8&amp;nbsp;&amp;nbsp;&amp;nbsp; 36&lt;/P&gt;
&lt;P&gt;Accoutn_Stat_9&amp;nbsp;&amp;nbsp;&amp;nbsp; 36&lt;/P&gt;
&lt;P&gt;Customer_det&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically i am trying to find the number columns from Hive tables using SAS.&lt;/P&gt;
&lt;P&gt;Could someone help me with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;vnreddy&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 14:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694247#M211712</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2020-10-26T14:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: count of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694287#M211728</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301412"&gt;@vnreddy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you will need a list of the table names.&amp;nbsp; This query should give you a list of the tables names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC	SQL;
	CONNECT	TO	ODBC	AS	Hive_DB	
		(NOPROMPT	=	"&amp;amp;Cnx_Str");

	SELECT	*			FROM	CONNECTION	TO	Hive_DB(SHOW TABLES);

	DISCONNECT	FROM	Hive_DB;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your connection string will typically be for a specific schema, so if you have multiple schema, then you will need to run multiple queries.&amp;nbsp; In the above example, I'm just letting the results of the query go to my results tab.&amp;nbsp; You would probably want to use the INTO option and have your results go into a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you get a list of tables, you could use a little macro, something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO	Describe_Formatted2(Table_Name);
	%TITLE(Describe formatted for &amp;amp;Table_Name);
	PROC	SQL;
		CONNECT	TO	ODBC	AS	Hive_DB	(NOPROMPT	=	"&amp;amp;Cnx_Str");

		SELECT	"&amp;amp;Table_Name"	AS	Table_Name
			,COUNT(1)	AS	Column_Count
			FROM	CONNECTION	TO	Hive_DB(DESCRIBE FORMATTED &amp;amp;Table_Name)
				;

		DISCONNECT	FROM	Hive_DB;
	QUIT;
%MEND	Describe_Formatted2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above macro will give you the name of the table and the count of the columns in the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would have to write a little macro to parse the macro variable containing the list of table names that the first query creates.&amp;nbsp; The parsing macro would then call the second macro to get the counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 16:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694287#M211728</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-26T16:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: count of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694310#M211732</link>
      <description>Hi Jim,&lt;BR /&gt;&lt;BR /&gt;I already have access to hadoop. We don't use ODBC connectivity.&lt;BR /&gt;I have tried using the above conect, i am not getting the list of tables.</description>
      <pubDate>Mon, 26 Oct 2020 17:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694310#M211732</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2020-10-26T17:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: count of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694314#M211735</link>
      <description>&lt;P&gt;Have you tried to use DICTIONARY.TABLES and/or DICTIONARY.COLUMNS if a library is assigned to HADOOP?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 18:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694314#M211735</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-26T18:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: count of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694316#M211736</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301412"&gt;@vnreddy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, those are just examples.&amp;nbsp; You would need to use the connect strings that your installation uses.&amp;nbsp; Most people are going to use Hadoop access engine instead of ODBC.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The examples I have given are using direct connections (Explicit pass through).&amp;nbsp;&amp;nbsp;To Kurt's point, assuming you have a Libname already allocated, you could do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC	SQL;
	SELECT	*	FROM	DICTIONARY.TABLES
		WHERE	LIBNAME='HIVEDB'
		;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above will list all the tables corresponding to the specified Libname.&amp;nbsp; Again, this is just an example.&amp;nbsp; My Libname for Hadoop is HiveDB.&amp;nbsp; You would need to change to whatever Libname you are using in your installation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get just a count of the columns, you could code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC	SQL;
	SELECT	COUNT(1)	AS	Column_Count
		FROM	DICTIONARY.Columns
			WHERE	LIBNAME='HIVEDB'
			;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 18:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-of-variables/m-p/694316#M211736</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-26T18:18:58Z</dc:date>
    </item>
  </channel>
</rss>

