<?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: Modifying the length of variables in a dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167131#M43279</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I specified the length when I merged the datasets and it worked fine! Thank you...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 May 2014 06:10:46 GMT</pubDate>
    <dc:creator>PTD_SAS</dc:creator>
    <dc:date>2014-05-21T06:10:46Z</dc:date>
    <item>
      <title>Modifying the length of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167129#M43277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How can I modify the length of all variables in a dataset without having to recreate them? Can it be done with Proc Datasets?&lt;/P&gt;&lt;P&gt;I have an old and a new dataset with the same variable names but diffrent lengths, when I merge them I get the warning "Multiple lengths specified for the variable xxxx. This may cause truncation of data".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 05:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167129#M43277</guid>
      <dc:creator>PTD_SAS</dc:creator>
      <dc:date>2014-05-21T05:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying the length of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167130#M43278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot change the length of and variable in an existing dataset. &lt;BR /&gt;That is one of the basics working with tables/RDBMS. Ask this to a DBA of a RDBMS and you will be see big eyes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can manipulate tables very easy with SAS there is an other way. Understand the way the PDV works using the datastep.&lt;/P&gt;&lt;P&gt;What I mean is you are knowing what it should be, use that knowledge.&lt;/P&gt;&lt;P&gt;data &amp;lt;your newname&amp;gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length &amp;lt;var ..&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp;&amp;nbsp; /* set length-s as needed */&lt;/P&gt;&lt;P&gt;&amp;nbsp; set/merge dsn1 dsn2 ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* will use length as you have set yourself, not of the input datasets */&lt;BR /&gt;run;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc append is designed for appending it has assumptions in the same way, assuming the base dataset is leading.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 06:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167130#M43278</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-05-21T06:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying the length of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167131#M43279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I specified the length when I merged the datasets and it worked fine! Thank you...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 06:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167131#M43279</guid>
      <dc:creator>PTD_SAS</dc:creator>
      <dc:date>2014-05-21T06:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying the length of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167132#M43280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a convenient way if you only need to SET them together.&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select * from old&lt;/P&gt;&lt;P&gt;&amp;nbsp; outer union corr&lt;/P&gt;&lt;P&gt;select * from new ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And If you only want to change the length of variables :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have1;
input name : $2. x $ id;
cards;
NB sds 1
RN sdft 1
;
run;
data have2;
input name $ x : $14. id;
cards;
NB sdsfsddfs 2
RN sdsdfsdfsder 3
BOTH sdsds 4
;
run;
/*First,we get the max length of variables in every tables */
proc sql;
create table temp as
select memname,name,max(length) as max_len
from dictionary.columns
where libname='WORK' and memname like 'HAVE%' and type='char'
group by name
order by memname,name;
quit;
/* then we use sql to change the variable's length fastly and easily.
we need to generate the sql code like:
proc sql;
alter table have1
modify name char(8),x char(14);
alter table have2
modify name char(8),x char(14);
.........
quit;
*/
data _null_;
set temp end=last;
by memname;
if _n_ eq 1 then call execute('proc sql;');
if first.memname then call execute('alter table '||memname||' modify ');
call execute(name||' char('||put(max_len,8.)||')');
if not last.memname then call execute(',');
else call execute(';');
if last then call execute('quit;');
run;
/*finally, get what we want */
data want;
set have1 have2 ;
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 May 2014 12:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Modifying-the-length-of-variables-in-a-dataset/m-p/167132#M43280</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-05-21T12:34:31Z</dc:date>
    </item>
  </channel>
</rss>

