<?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 Append problem when BASE has never been initialize in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498320#M132399</link>
    <description>&lt;P&gt;Obviously, your "finaltest" data set will always be empty when you run this code, because of the last couple of statements:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data finaltest;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Sep 2018 08:16:27 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2018-09-24T08:16:27Z</dc:date>
    <item>
      <title>Proc Append problem when BASE has never been initialize</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498294#M132383</link>
      <description>&lt;P&gt;Hi, I am trying to append a lot of datasets in a recursive macro.&lt;/P&gt;&lt;P&gt;However, when i set the BASE as dataset that has not been initialize, it will not produce any result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro list_files(dir,ext);					
	%local filrf rc did memcnt name i;				
	%let rc=%sysfunc(filename(filrf,&amp;amp;dir));				
	%let did=%sysfunc(dopen(&amp;amp;filrf));				
					
	%if &amp;amp;did eq 0 %then				
		%do;			
			%put Directory &amp;amp;dir cannot be open or does not exist;		
					
			%return;		
		%end;			
					
	%do i = 1 %to %sysfunc(dnum(&amp;amp;did));				
		%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));			
					
		%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then			
			%do;		
				%put &amp;amp;dir/&amp;amp;name;	
				%let file_name =  %qscan(&amp;amp;name,1,.);	
				%put &amp;amp;file_name;	
				/*Alfred added this*/	
			PROC IMPORT OUT=WORK.out DATAFILE= "&amp;amp;dir/&amp;amp;name" 		
		/*excelout*/			
            DBMS=csv REPLACE;					
			delimiter='09'x;		
			getnames=no;		
		RUN;			
		proc contents data=out noprint out=data_info /*(keep = name varnum)*/;			
		run;			
					
		 data _null_;			
			set data_info;		
			call symputx(compress("col"||VARNUM),compress(NAME));		
			call symputx("cnt",_n_);		
		run;			
					
					
					
					
		
					
		data _null_;			
		set WORK.out (obs=2);			
			if _n_ = 2 then do;		
			tcnt = 0;		
				%do j=1 %to &amp;amp;cnt;	
					if &amp;amp;&amp;amp;col&amp;amp;j not in ("","Total") then do;
					trxm = &amp;amp;&amp;amp;col&amp;amp;j;
					call symputx(compress("trxm"||tcnt),compress(trxm));
					call symputx("tcnt",tcnt);
					tcnt+1;
					end;
				%end;	
			end;		
		run;			
		 			
	
		
					
		
					
					
					
		data test (drop=			
		%do k=1 %to &amp;amp;cnt;			
		&amp;amp;&amp;amp;col&amp;amp;k..			
		%end;			
		);			
					
		length station $10 voltage $10 year 8 month $20 transformer $10			
		Day $20 Date Time MW_Imp MW_Exp MVAR_Imp MVAR_Exp MVA Power_Factor 8;			
		format Time hhmm.;			
		set 			
		out end=last;			
					
		output;			
		%end;			
		end;			
		run;			
	
							
		proc append base=finaltest data=test FORCE;			
		run;			
				
		data finaltest;
		run;	&lt;/PRE&gt;&lt;P&gt;Sample code as above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are not the full code. What i want to do is append data everytime it loops. I do not want to assign the loop counter for every dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moreover, is it necessary to write a dataset and define column names for "finaltest" the BASE table first?&lt;/P&gt;&lt;P&gt;I read somewhere that BASE table doesnt have to initialize first.&lt;/P&gt;&lt;P&gt;Correct me if i am wrong.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498294#M132383</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-09-24T07:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append problem when BASE has never been initialize</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498303#M132389</link>
      <description>&lt;P&gt;Not going to answer the question as this has been talked about time and time again.&amp;nbsp; Use the inbuilt SAS function called&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;by group processing&lt;/STRONG&gt;&lt;/U&gt; rather than create many same datasets and then appending.&amp;nbsp; This will save you disk space, read/writes, enable you to write short concise coding.&amp;nbsp; None of the code you presented is necessary, you have a bunch of csv files, you need to import, therefore write one datastep import - key to gettting data correctly in (import guesses), then use a wildcard in the infile to read all the files, very simple easy coding:&lt;/P&gt;
&lt;PRE&gt;data want;
  infile "pathtofiles/*.csv" dlm=",";
  length...;
  format...;
  informat...;
  input...;
run;&lt;/PRE&gt;
&lt;P&gt;Dont actually even need to use by group processing here.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498303#M132389</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-24T07:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append problem when BASE has never been initialize</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498320#M132399</link>
      <description>&lt;P&gt;Obviously, your "finaltest" data set will always be empty when you run this code, because of the last couple of statements:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data finaltest;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Sep 2018 08:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498320#M132399</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-09-24T08:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append problem when BASE has never been initialize</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498431#M132451</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;However, when i set the BASE as dataset that has not been initialize, it will not produce any result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;That is wrong, PROC APPEND does not require the base data set to exist before creation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append base=testR12345 data=sashelp.class;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Log:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;1 proc append base=testR12345 data=sashelp.class;run;&lt;BR /&gt;NOTE: Writing HTML Body file: sashtml.htm&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4" color="#339966"&gt;&lt;STRONG&gt;NOTE: Appending SASHELP.CLASS to WORK.TESTR12345.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="4" color="#339966"&gt;&lt;STRONG&gt;NOTE: BASE data set does not exist. DATA file is being copied to BASE file.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;NOTE: The data set WORK.TESTR12345 has 19 observations and 5 variables.&lt;BR /&gt;NOTE: PROCEDURE APPEND used (Total process time):&lt;BR /&gt; real time 3.95 seconds&lt;BR /&gt; cpu time 0.28 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 15:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498431#M132451</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-24T15:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append problem when BASE has never been initialize</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498601#M132546</link>
      <description>&lt;P&gt;Hi Reeza, thanks for the clarification. If i do not initialize the base table, how do i output it out? I am doing it in EG but not want to use proc sql.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 21:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-problem-when-BASE-has-never-been-initialize/m-p/498601#M132546</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-09-24T21:35:51Z</dc:date>
    </item>
  </channel>
</rss>

