<?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 LENGTH? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598886#M172773</link>
    <description>&lt;P&gt;I solved it using eval.&amp;nbsp; Thanks all&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2019 01:41:54 GMT</pubDate>
    <dc:creator>texasmfp</dc:creator>
    <dc:date>2019-10-24T01:41:54Z</dc:date>
    <item>
      <title>Dynamic LENGTH?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598299#M172538</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to set a length based on a calculated value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if I read in 36 variables of 6 characters/variable and, concatenate those to a new variable that has a total length of 216.&amp;nbsp; Now the default is 200 characters, so I will get a truncation message.&amp;nbsp; Easily solved by setting a length&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;length concatvar $ 216;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if change the input to just 30 variables of 6 characters each, and concatenate, the new variable is 180 characters.&amp;nbsp; If the length had previously been set at 216, that would leave blanks.&amp;nbsp; And, if I ran it a third time concatenating 50 variables, that is a length of 300.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to avoid manually calculating and setting the length; making it dynamic, based on a calculated number (i.e., length concatvar $ (calculated number)?&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;&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>Tue, 22 Oct 2019 02:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598299#M172538</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2019-10-22T02:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic LENGTH?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598313#M172543</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try the code below ad then use the macrovariable &amp;amp;&lt;CODE class=" language-sas"&gt;total_length&lt;/CODE&gt;&amp;nbsp;in a length statement in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list_var = /* list your variables. E.g. var1 var2 var3 var4 */;

data _Null_;
	set sample; /*specify your dataset*/
	array variables(*) $ &amp;amp;list_var ;
	do i=1 to dim(variables);
		total_lenght + length(variables(i));
	end;
	call symputx("total_length",total_lenght);
run;

 
data want;
	set sample;
	length new_var $ &amp;amp;total_length;
	....;
run;&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Oct 2019 04:41:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598313#M172543</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-10-22T04:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic LENGTH?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598322#M172546</link>
      <description>&lt;P&gt;You can get the defined length of a variable from &lt;FONT face="courier new,courier"&gt;dictionary.columns&lt;/FONT&gt; in &lt;FONT face="courier new,courier"&gt;proc sql&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;So you can run this&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select sum(length) into :concat_length
from dictionary.columns
where libname = 'XXX' and memname = 'YYY' and /* insert condition to identify your character columns here */;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;to later use &lt;FONT face="courier new,courier"&gt;&amp;amp;concat_length&lt;/FONT&gt; in your code.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2019 05:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598322#M172546</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-22T05:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic LENGTH?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598886#M172773</link>
      <description>&lt;P&gt;I solved it using eval.&amp;nbsp; Thanks all&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 01:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-LENGTH/m-p/598886#M172773</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2019-10-24T01:41:54Z</dc:date>
    </item>
  </channel>
</rss>

