<?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: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625239#M184268</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your first SQL procedure is not delivering any results. Consequently the macro variable cnt is not defined and SAS issues the warning&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Output-: WARNING: Apparent symbolic reference CNT not resolved.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Define any variable created by SQL explicitly as local or global to solve the Problem:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local cnt var_cnt INPUT_COLUMN_S clmn_cnt INPUT_COLUMN_M;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF %SYSFUNC(INPUTN(&amp;amp;var_cnt,2.)) GT 0 %THEN %DO;
   %DO cc=1 %to &amp;amp;cnt.;
      %local var&amp;amp;cc.;
   %END;
[...]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2020 11:50:16 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2020-02-17T11:50:16Z</dc:date>
    <item>
      <title>Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625215#M184260</link>
      <description>&lt;P&gt;Hii..&lt;/P&gt;&lt;P&gt;I am trying to write the code which will read all the files from the specified location irrespective of the&amp;nbsp; file size and No. of&amp;nbsp; columns in the Source file . I'm facing an issue regarding execution of "proc Sql select into:" statement . proc Sql&amp;nbsp; not getting executed after restarting my sas session. But if i commit&amp;nbsp; mistake&amp;nbsp; for example if i changed Inputn() to nputn() and run the macro and now if i correct my mistake&amp;nbsp; nputn() to inputn() then if i run the macro then my code running and gives correct output .I'm not getting where i'm making mistake. My Entire Code is Below....&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro All_process(file_src1, cont1);

	&lt;FONT color="#FF0000"&gt;proc Sql;/*Not getting Executed After restarting My SAS Session */
		select count(*) into:cnt from Sample_Mapping where filename="&amp;amp;file_src1";
	quit;&lt;/FONT&gt;
	

	%put &amp;amp;=cnt;


&lt;FONT color="#FF6600"&gt;	%if %SYSFUNC(INPUTN(&amp;amp;cnt,2.)) &amp;gt; 0 %then
%Do;&lt;/FONT&gt; &lt;FONT color="#FF0000"&gt;/*&lt;FONT color="#999999"&gt;if change Inputn() to nputn() run macro then if correct my mistake nputn() to inputn() then codes runs&lt;/FONT&gt;*/&lt;/FONT&gt;

			Data SAMP.&amp;amp;file_src1._mand_column;/*Creating Table which will consist only mandatory columns of the File*/
				set Samp.Sample_Mapping (WHERE=(STRIP(MANDATORY)='Y' 
					AND(Filename)="&amp;amp;file_src1"));
			run;
			
			data _null_;
	         set Samp.&amp;amp;file_src1._mand_column;
	          call symputx('Filename', strip(Filename));
	           CALL SYMPUTX('INPUT_FILE_Path', STRIP(Extract_Location) ||STRIP(Filename) ||'.csv');
	            Call Symputx('STG_TBL_NAME', STRIP(ST_TBL_NAME));
	            CALL SYMPUTX('TBL', STRIP(ST_TBL_NAME));
              run;
              
             %put &amp;amp;=TBL;
              Data samp.&amp;amp;TBL._detail_frm_mapping_sheet;/*Get all columns of table from mapping sheet and their Detail*/
	           set Sample_mapping;
	            where strip(filename)="&amp;amp;file_src1";
	           run;
	          
	    &lt;FONT color="#FF0000"&gt;     proc Sql;&lt;FONT color="#999999"&gt;/*counting the total number of column  of table from mapping Sheet*/&lt;/FONT&gt;
	          select Count(*) into: var_cnt from samp.&amp;amp;TBL._detail_frm_mapping_sheet where Column_name not in (" ","Batch_id", "Batch_date");
             quit;
     
  &lt;FONT color="#FF9900"&gt;       %IF %SYSFUNC(INPUTN(&amp;amp;var_cnt,2.)) GT 0 %THEN %DO;&lt;/FONT&gt;&lt;/FONT&gt;
             PROC SQL;
	         SELECT Column_Name 
		          INTO: Column_Name1 -: Column_Name%SYSFUNC(COMPRESS(&amp;amp;var_cnt)) FROM samp.&amp;amp;TBL._detail_frm_mapping_sheet
		            WHERE Column_Name NOT IN  (" ", "Batch_id", "Batch_date");
	             SELECT Column_Name INTO: INPUT_COLUMN_S SEPARATED BY " " FROM samp.&amp;amp;TBL._detail_frm_mapping_sheet
		            WHERE Column_Name NOT IN  (" ", "Batch_id", "Batch_date");
                 QUIT;
      %END;
    
%Reading_source_file;
   /*  DATA samp.&amp;amp;Filename._Source;
		
		 INFILE "&amp;amp;INPUT_FILE_Path" LRECL=2500 DELIMITER=',' DSD MISSOVER FIRSTOBS=2;

		 %DO K=1 %TO &amp;amp;var_cnt;
			ATTRIB	&amp;amp;&amp;amp;Column_Name&amp;amp;K LENGTH=$300 FORMAT=$300. INFORMAT=$300.;
		  %END;
		   INPUT &amp;amp;INPUT_COLUMN_S;
	  RUN;
	 */
	&lt;FONT color="#FF0000"&gt;proc Sql;
	select Count(*) into: clmn_cnt from SAMP.&amp;amp;file_src1._mand_column;
     quit;&lt;/FONT&gt;&lt;FONT color="#FF9900"&gt;%IF %sysfunc(InputN(&amp;amp;clmn_cnt,2.0)) GT 0 %THEN %DO;&lt;/FONT&gt;
PROC SQL;
	SELECT Column_Name 
		INTO: Column_Name1 -: Column_Name%SYSFUNC(COMPRESS(&amp;amp;clmn_cnt)) FROM SAMP.&amp;amp;file_src1._mand_column;
	SELECT Column_Name INTO: INPUT_COLUMN_M SEPARATED BY " " FROM 
		SAMP.&amp;amp;file_src1._mand_column;
quit;
 %end;
 
 
 PROC SORT DATA = samp.&amp;amp;Filename._Source
                       OUT = &amp;amp;Filename._DUPVALCHECK
                       UNIQUEOUT = &amp;amp;filename._Unique_rows  NOUNIKEY;
                BY _ALL_;
           RUN;
           
           
  DATA &amp;amp;Filename._DUPVALCHECK; 
                 length Source_Filename $ 256 ;
                  LENGTH REJECT_REASON $ 256; 
                SET &amp;amp;Filename._DUPVALCHECK;
                REJECT_REASON = "Duplicate Record";
                Source_Filename="&amp;amp;Filename";
           RUN; 
           	



data &amp;amp;filename._Final_Valdt_Clmn_Table(drop= REJECT_REASON flag Source_Filename) Error_record_table(drop=flag) ;
 length Source_Filename $ 256 ;
 LENGTH REJECT_REASON $ 256;
 set &amp;amp;filename._Unique_rows;
flag=0;
Process_Date="&amp;amp;Sysdate9";
 %do i=1 %to&amp;amp;clmn_cnt;
     if missing(&amp;amp;&amp;amp;Column_Name&amp;amp;i) then
		do;
		 flag=flag+1;
           IF REJECT_REASON EQ "" THEN 
                 DO;
				 REJECT_REASON="&amp;amp;&amp;amp;Column_Name&amp;amp;i";
				  END;
			     ELSE
				    DO;
				 REJECT_REASON=CATS(REJECT_REASON, ',', "&amp;amp;&amp;amp;Column_Name&amp;amp;i");
				    END;
	          end;
		else
				do;
					flag=flag;
				end;
	%end;

		IF REJECT_REASON NE "" THEN
			DO;
				REJECT_REASON=CATX('  ',REJECT_REASON, 
					"  Mandatory field/s contain missing values");
					Source_Filename="&amp;amp;Filename";
			END;

		if flag=0 then
			output &amp;amp;filename._Final_Valdt_Clmn_Table;
		else
			output Error_record_table;
	
	run;
	

  
 
DATA Final_Error_Record_Table;
set &amp;amp;Filename._DUPVALCHECK Error_record_table;
Process_Date="&amp;amp;sysdate9";
run;

%end;
	%else
		%do;
			%put "Table dosn't Exist";
		%end;
%mend All_process;



%macro Reading_source_file;
DATA samp.&amp;amp;Filename._Source;
		/**/
		 INFILE "&amp;amp;INPUT_FILE_Path" LRECL=2500 DELIMITER=',' DSD MISSOVER FIRSTOBS=2;

		 %DO K=1 %TO &amp;amp;var_cnt;
			ATTRIB	&amp;amp;&amp;amp;Column_Name&amp;amp;K LENGTH=$300 FORMAT=$300. INFORMAT=$300.;
		  %END;
		   INPUT &amp;amp;INPUT_COLUMN_S;
	  RUN;
%mend Reading_source_file;


libname SAMP Base '/sasdata/TestCode';
filename folder "/home/sasdemo/Test11/"; 
proc import datafile='/home/sasdemo/MappTemp1.csv' out=sample_Mapping dbms=csv 
		replace;
run;

Data Samp.Sample_Mapping;
	set sample_mapping(where=(filename is not null) );
	Mandatory=upcase(Mandatory);
	ERR_LIBREF='STGERROR';
	STG_LIBREF='SASSTAGE';
run;




data _null_;
	list=dopen("folder");/*opening the given location folder reading all the files */

	do i=1 to dnum(list);
	cont1=i;
		File_src=substr(trim(dread(list, i)), 1, index(trim(dread(list, i)), '.')-1);
		put File_src=;
		call execute('%All_process(file_src1='||strip(file_src)||',cont1='||strip(cont1)||');');
		put i=;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#808080"&gt;&lt;FONT color="#FF0000"&gt;Output-:&lt;/FONT&gt; WARNING: Apparent symbolic reference CNT not resolved.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 09:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625215#M184260</guid>
      <dc:creator>Shubham5497</dc:creator>
      <dc:date>2020-02-17T09:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625227#M184264</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;proc Sql not getting executed after restarting my sas session.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;There is no reason for this. It's far more likely that your where clause returns no records.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 10:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625227#M184264</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-17T10:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625229#M184265</link>
      <description>&lt;P&gt;Is there any alternative of "proc sql select into :" statement in sas through which we can create the&amp;nbsp; macro variable dynamically just like proc sql select into:?&amp;nbsp; some result which got when i googled&amp;nbsp; is to use Proc freq procedure but i don't know&amp;nbsp; how will i store that value in macro&amp;nbsp; variable so that i can use that in further code&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 11:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625229#M184265</guid>
      <dc:creator>Shubham5497</dc:creator>
      <dc:date>2020-02-17T11:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625230#M184266</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about doing something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local cnt;
%let cnt = 0;
proc Sql;
	select count(*) into:cnt from Sample_Mapping where filename="&amp;amp;file_src1";
quit;


%put &amp;amp;=cnt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 11:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625230#M184266</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-17T11:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625232#M184267</link>
      <description>&lt;P&gt;I tried that as well but not working..&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 11:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625232#M184267</guid>
      <dc:creator>Shubham5497</dc:creator>
      <dc:date>2020-02-17T11:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625239#M184268</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your first SQL procedure is not delivering any results. Consequently the macro variable cnt is not defined and SAS issues the warning&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Output-: WARNING: Apparent symbolic reference CNT not resolved.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Define any variable created by SQL explicitly as local or global to solve the Problem:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local cnt var_cnt INPUT_COLUMN_S clmn_cnt INPUT_COLUMN_M;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF %SYSFUNC(INPUTN(&amp;amp;var_cnt,2.)) GT 0 %THEN %DO;
   %DO cc=1 %to &amp;amp;cnt.;
      %local var&amp;amp;cc.;
   %END;
[...]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 11:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625239#M184268</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2020-02-17T11:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625240#M184269</link>
      <description>&lt;P&gt;Add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cnt=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the start of your macro, so you have &amp;amp;cnt defined even if the SQL returns no rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;VERY STRONG HINT:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Always start with working SAS code &lt;EM&gt;before&lt;/EM&gt; you try to make it dynamic in a macro.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 11:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625240#M184269</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-17T11:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625243#M184270</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and how about making it a bit simpler:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local cnt;
%let cnt = 0;
proc Sql;
	select count(*) into:cnt from Sample_Mapping where filename="&amp;amp;file_src1";
quit;


%put &amp;amp;=cnt;

%if %sysevalf(&amp;amp;cnt &amp;gt; 0) %then
%Do;
/*...*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 12:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625243#M184270</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-17T12:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql  code not Running Inside Sas Macro code After Restarting  My SAS Session</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625428#M184327</link>
      <description>&lt;P&gt;If the macro variable might be empty, one way to address that is to test&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; %if 0&amp;amp;cnt &amp;gt; 2 %then&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 20:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-code-not-Running-Inside-Sas-Macro-code-After-Restarting/m-p/625428#M184327</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-17T20:18:30Z</dc:date>
    </item>
  </channel>
</rss>

