<?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: Dynamic Variable Length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284243#M58005</link>
    <description>&lt;P&gt;Try informat $VARYING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename File_Dir pipe "dir &amp;amp;Dir";

data File_List;
infile File_Dir length=len lrecl=1000;

input folderlist $varying1000. len ;
.............
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Jul 2016 04:42:14 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-07-14T04:42:14Z</dc:date>
    <item>
      <title>Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284196#M57978</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm reading file names into a dataset from a directory:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename File_Dir pipe "dir &amp;amp;Dir";

data File_List;
infile File_Dir truncover;

input folderlist $char1000.;

length  
folder file $75.
extension $6. 
date 8;

retain folder;
if index(folderlist,'Directory') &amp;gt; 0 then folder = substr(folderlist,14,180);

if scan(folderlist,2,'.') ne ' ' then do;
	file = strip(scan(substr(folderlist,40,160),1,'.'));
	extension = upcase(scan(strip(folderlist),-1,'.'));
	date = mdy(input(substr(folderlist,1,2),8.),input(substr(folderlist,4,2),8.),input(substr(folderlist,7,4),8.));
	size = input(strip(substr(folderlist,30,10)),comma32.);
	end;

if date ne .;
if findc(extension,'~%%$') = 0;

keep Folder File Extension Date ;

format Date mmddyy10.;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My problem is that no matter how I try to strip away blank spaces from the File name they stay at a length of 75. This is creating file name issues later on when I try to export updated versions of the files using the same name.&lt;/P&gt;
&lt;P&gt;I'm getting something like "Example File Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.xlsx"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried strip, compress, trim, etc and cant seem to figure out how to get rid of that extra space. I can manully change the length of the File variable but that's defeating the purpose. Is there a way to dynamically change the length of the File variable to the max length of File?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate the thoughts. thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 21:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284196#M57978</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2016-07-13T21:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284197#M57979</link>
      <description>&lt;P&gt;I do not see where you are combining FILE and Extension.&lt;/P&gt;
&lt;P&gt;I would try&lt;/P&gt;
&lt;P&gt;File_Extension = cats(file,'.', extension);&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 21:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284197#M57979</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-13T21:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284199#M57981</link>
      <description>&lt;P&gt;SAS character strings have a fixed length. Saying&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;str = trim(str);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does nothing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must do the trim of strip within the expression where you concatenate the substrings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Concatenation functions CATS, CATX and CATT do that automatically for you. Check them out!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 21:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284199#M57981</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-13T21:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284243#M58005</link>
      <description>&lt;P&gt;Try informat $VARYING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename File_Dir pipe "dir &amp;amp;Dir";

data File_List;
infile File_Dir length=len lrecl=1000;

input folderlist $varying1000. len ;
.............
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jul 2016 04:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284243#M58005</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-14T04:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284328#M58024</link>
      <description>&lt;P&gt;Sorry if I wasnt clear in my initial post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once I pull the diretory file names into a data set I take the most recenetly added file, grab the name and then the file itself:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select a.File into : Recent 
from File_List a
left join (select Max(Date) as Date format=mmddyys10. 
			from File_List where extension = "XLSX") b 
			on a.Date = b.Date
where (a.Date = b.Date);
quit;
%put &amp;amp;Recent;



proc import 
out = CCR
datafile = "&amp;amp;Dir&amp;amp;Recent"
dbms = xlsx replace;
getnames = YES;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After some modifications and field additions the file is then exported.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's at this time that I'm getting the extra spaces in the file name. "Example File Data &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .xlsx"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No matter what I seem to do I can't get rid of it. The field is as long as the value I specify on my length statement when I input the directory information. I tried using $Varying1000.&amp;nbsp;as a&amp;nbsp;format but it was giving me errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc export
data = TCL
outfile = "&amp;amp;output\Updated_&amp;amp;Recent..xlsx"
DBMS = EXCEL replace;
SHEET = "data";
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jul 2016 13:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284328#M58024</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2016-07-14T13:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284335#M58028</link>
      <description>&lt;P&gt;Add the keyword &lt;STRONG&gt;trimmed&lt;/STRONG&gt; to your &lt;STRONG&gt;select into&lt;/STRONG&gt; clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;File&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; : Recent &lt;FONT color="#993300"&gt;trimmed&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 13:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284335#M58028</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-14T13:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Variable Length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284368#M58042</link>
      <description>Verified. Thanks. &lt;BR /&gt;&lt;BR /&gt;That was killing me.</description>
      <pubDate>Thu, 14 Jul 2016 15:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Variable-Length/m-p/284368#M58042</guid>
      <dc:creator>Ody</dc:creator>
      <dc:date>2016-07-14T15:18:35Z</dc:date>
    </item>
  </channel>
</rss>

