<?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 Need to set Table name in to the column for each record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-set-Table-name-in-to-the-column-for-each-record/m-p/558131#M155734</link>
    <description>&lt;P&gt;I have one program in which i need to monitor the table on daily basis.&lt;/P&gt;&lt;P&gt;I have created a table where i am inserting table names which i need to monitor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CREATE TABLE LIST_OF_TABLES (TABLE_NAME_COLUMN CHAR(20));

   INSERT INTO LIST_OF_TABLES
   			VALUES("EXAMPLE_TABLE1")
			VALUES("EXAMPLE_TABLE2")
			VALUES("EXAMPLE_TABLE3");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now i have written a macro to iterate the table&amp;nbsp;&lt;CODE class=" language-sas"&gt;"LIST_OF_TABLES"&lt;/CODE&gt;&amp;nbsp;and select some columns from each table and prepare TEMP data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO MONITORING;
	
	%DO I=1 %TO &amp;amp;TABLE_COUNT;
		
		PROC SQL;

		 insert into WORK.TEMP (last_date_of_month,date,status)  
		 
		 /*I need to insert table name in a column for each record.
		I have a veriable &amp;amp;&amp;amp;TABLE_NAME&amp;amp;I in which i have table name and i am iterating and getting each table name and preparing work.temp data set*/
			
			SELECT distinct DT.last_of_month format=Date9.,
					DWT.date format=Date9.,
					case
        			when date is NULL then '0'
					when date is NOT NULL then '1'
					end as status
					
			FROM DATES DT
			left join WORK.&amp;amp;&amp;amp;TABLE_NAME&amp;amp;I as DWT
			on DT.last_of_month = DWT.date;

		run;
		QUIT;


	%END;
	RUN;
%MEND;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have commented in the program where i need to insert / add column of table name.&lt;/P&gt;&lt;P&gt;For reference here is the full code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = %sysfunc(intnx(week,%sysfunc(today()),-2,e),date9.);
%let end_date = %sysfunc(intnx(week,%sysfunc(today()),0,e),date9.);

%let days = intck('day',"&amp;amp;start_date."d,"&amp;amp;end_date."d);

 data dates;
 do d = 0 to &amp;amp;days.;
 first_of_month = intnx('DAY',"&amp;amp;start_date."d,d,'s');
 last_of_month = intnx('DAY',"&amp;amp;start_date."d,d,'e');
 output;
 end;
 run;
proc sql;
   CREATE TABLE LIST_OF_TABLES (TABLE_NAME_COLUMN CHAR(20));

   INSERT INTO LIST_OF_TABLES
   			VALUES("EXAMPLE_TABLE1")
			VALUES("EXAMPLE_TABLE2")
			VALUES("EXAMPLE_TABLE3");

	SELECT LEFT(PUT(COUNT(TABLE_NAME_COLUMN),4.0)) INTO :TABLE_COUNT FROM LIST_OF_TABLES;
	SELECT TABLE_NAME_COLUMN INTO :TABLE_NAME1 - :TABLE_NAME&amp;amp;TABLE_COUNT FROM LIST_OF_TABLES;

	
	create table TEMP (last_date_of_month num informat=date9. format=date9.,
					  date num informat= date9. format= date9.,
					  status char(20),
					  table_name char(20));
quit;


%MACRO MONITORING;
	
	%DO I=1 %TO &amp;amp;TABLE_COUNT;
		
		PROC SQL;

		 insert into WORK.TEMP (last_date_of_month,date,status)  

/*I need to insert table name in a column for each record.																	I have a veriable &amp;amp;&amp;amp;TABLE_NAME&amp;amp;I in which i have table name and i am iterating and getting each table name and preparing work.temp data set*/
			
			SELECT distinct DT.last_of_month format=Date9.,
					DWT.date format=Date9.,
					case
        			when date is NULL then '0'
					when date is NOT NULL then '1'
					end as status
					
			FROM DATES DT
			left join WORK.&amp;amp;&amp;amp;TABLE_NAME&amp;amp;I as DWT
			on DT.last_of_month = DWT.date;

		run;
		QUIT;


	%END;
	RUN;
%MEND;

%MONITORING;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 May 2019 15:12:41 GMT</pubDate>
    <dc:creator>priya_05</dc:creator>
    <dc:date>2019-05-12T15:12:41Z</dc:date>
    <item>
      <title>Need to set Table name in to the column for each record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-set-Table-name-in-to-the-column-for-each-record/m-p/558131#M155734</link>
      <description>&lt;P&gt;I have one program in which i need to monitor the table on daily basis.&lt;/P&gt;&lt;P&gt;I have created a table where i am inserting table names which i need to monitor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CREATE TABLE LIST_OF_TABLES (TABLE_NAME_COLUMN CHAR(20));

   INSERT INTO LIST_OF_TABLES
   			VALUES("EXAMPLE_TABLE1")
			VALUES("EXAMPLE_TABLE2")
			VALUES("EXAMPLE_TABLE3");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now i have written a macro to iterate the table&amp;nbsp;&lt;CODE class=" language-sas"&gt;"LIST_OF_TABLES"&lt;/CODE&gt;&amp;nbsp;and select some columns from each table and prepare TEMP data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO MONITORING;
	
	%DO I=1 %TO &amp;amp;TABLE_COUNT;
		
		PROC SQL;

		 insert into WORK.TEMP (last_date_of_month,date,status)  
		 
		 /*I need to insert table name in a column for each record.
		I have a veriable &amp;amp;&amp;amp;TABLE_NAME&amp;amp;I in which i have table name and i am iterating and getting each table name and preparing work.temp data set*/
			
			SELECT distinct DT.last_of_month format=Date9.,
					DWT.date format=Date9.,
					case
        			when date is NULL then '0'
					when date is NOT NULL then '1'
					end as status
					
			FROM DATES DT
			left join WORK.&amp;amp;&amp;amp;TABLE_NAME&amp;amp;I as DWT
			on DT.last_of_month = DWT.date;

		run;
		QUIT;


	%END;
	RUN;
%MEND;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have commented in the program where i need to insert / add column of table name.&lt;/P&gt;&lt;P&gt;For reference here is the full code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_date = %sysfunc(intnx(week,%sysfunc(today()),-2,e),date9.);
%let end_date = %sysfunc(intnx(week,%sysfunc(today()),0,e),date9.);

%let days = intck('day',"&amp;amp;start_date."d,"&amp;amp;end_date."d);

 data dates;
 do d = 0 to &amp;amp;days.;
 first_of_month = intnx('DAY',"&amp;amp;start_date."d,d,'s');
 last_of_month = intnx('DAY',"&amp;amp;start_date."d,d,'e');
 output;
 end;
 run;
proc sql;
   CREATE TABLE LIST_OF_TABLES (TABLE_NAME_COLUMN CHAR(20));

   INSERT INTO LIST_OF_TABLES
   			VALUES("EXAMPLE_TABLE1")
			VALUES("EXAMPLE_TABLE2")
			VALUES("EXAMPLE_TABLE3");

	SELECT LEFT(PUT(COUNT(TABLE_NAME_COLUMN),4.0)) INTO :TABLE_COUNT FROM LIST_OF_TABLES;
	SELECT TABLE_NAME_COLUMN INTO :TABLE_NAME1 - :TABLE_NAME&amp;amp;TABLE_COUNT FROM LIST_OF_TABLES;

	
	create table TEMP (last_date_of_month num informat=date9. format=date9.,
					  date num informat= date9. format= date9.,
					  status char(20),
					  table_name char(20));
quit;


%MACRO MONITORING;
	
	%DO I=1 %TO &amp;amp;TABLE_COUNT;
		
		PROC SQL;

		 insert into WORK.TEMP (last_date_of_month,date,status)  

/*I need to insert table name in a column for each record.																	I have a veriable &amp;amp;&amp;amp;TABLE_NAME&amp;amp;I in which i have table name and i am iterating and getting each table name and preparing work.temp data set*/
			
			SELECT distinct DT.last_of_month format=Date9.,
					DWT.date format=Date9.,
					case
        			when date is NULL then '0'
					when date is NOT NULL then '1'
					end as status
					
			FROM DATES DT
			left join WORK.&amp;amp;&amp;amp;TABLE_NAME&amp;amp;I as DWT
			on DT.last_of_month = DWT.date;

		run;
		QUIT;


	%END;
	RUN;
%MEND;

%MONITORING;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2019 15:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-set-Table-name-in-to-the-column-for-each-record/m-p/558131#M155734</guid>
      <dc:creator>priya_05</dc:creator>
      <dc:date>2019-05-12T15:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need to set Table name in to the column for each record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-set-Table-name-in-to-the-column-for-each-record/m-p/558525#M155883</link>
      <description>&lt;P&gt;The question is unclear. Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  insert into WORK.TEMP (LAST_DATE_OF_MONTH,DATE,STATUS)  
  select distinct DT.last_of_month           format=date9.
                 ,DWT.date                   format=date9.
                 ,"&amp;amp;&amp;amp;TABLE_NAME&amp;amp;I"   as TABLE
                 ,(DATE is not NULL) as STATUS
  from DATES DT
  left join WORK.&amp;amp;&amp;amp;TABLE_NAME&amp;amp;I as DWT
  on DT.last_of_month = DWT.date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 03:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-set-Table-name-in-to-the-column-for-each-record/m-p/558525#M155883</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-14T03:47:58Z</dc:date>
    </item>
  </channel>
</rss>

