<?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: automatic update of variable attributes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48200#M9948</link>
    <description>Hi Peter&lt;BR /&gt;
&lt;BR /&gt;
I was very aware that the code I suggested doesn't handle character/numeric missmatch - and it's on purpose that my code will throw an error for such a case(enough is enough...).&lt;BR /&gt;
&lt;BR /&gt;
Also on purpose I've set up the example in a way that strings get truncated - just to show that may be modifying variable lengths is not really the solution to the problem.&lt;BR /&gt;
&lt;BR /&gt;
I believe what one should do is to define appropriate variable lengths explicitly (attrib statement) so length matching issues won't occur at all.&lt;BR /&gt;
&lt;BR /&gt;
The amendment to the code I've posted could be to compare variable lengths between base and transaction data set and change the length in the data set where it's shorter.&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
    <pubDate>Wed, 27 Apr 2011 11:27:09 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2011-04-27T11:27:09Z</dc:date>
    <item>
      <title>automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48193#M9941</link>
      <description>Hello, need your help.&lt;BR /&gt;
&lt;BR /&gt;
I have two datasets (A and B) which have same variable names but different length and type. Periodically, I need to add B records to A. How can I automatically update B variable attributes to the same of A? Thanks.</description>
      <pubDate>Mon, 11 Apr 2011 19:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48193#M9941</guid>
      <dc:creator>cbsxb</dc:creator>
      <dc:date>2011-04-11T19:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48194#M9942</link>
      <description>this post went unanswered from a coupleof weeks ago.  Did you get the solution that you needed?  If not are either of your data sets of a size that allow pre processing?</description>
      <pubDate>Mon, 25 Apr 2011 05:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48194#M9942</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-04-25T05:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48195#M9943</link>
      <description>Hi.&lt;BR /&gt;
ArtC.I only solve part question ,namely only make all variables in A and B to have the same length.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
 set sashelp.class;&lt;BR /&gt;
 keep name sex weight;&lt;BR /&gt;
run;&lt;BR /&gt;
data b;&lt;BR /&gt;
length name $ 50 sex $ 20 weight 3;&lt;BR /&gt;
  name='Peter'; sex='M';  weight=56.3; output;&lt;BR /&gt;
  name='Patrick'; sex='M';weight=56.2;output;&lt;BR /&gt;
  name='ArtC'; sex='M'; weight=69.9;output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%let table_a=A;&lt;BR /&gt;
%let table_b=B;&lt;BR /&gt;
&lt;BR /&gt;
%macro alter;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select cat( name ,case (type)&lt;BR /&gt;
                   when ('char') then cat(' char(',length,')')&lt;BR /&gt;
                   when ('num') then cat(' ',length)&lt;BR /&gt;
                 end   )&lt;BR /&gt;
    into : change separated by ','&lt;BR /&gt;
   from dictionary.columns&lt;BR /&gt;
    where libname='WORK' and memname="&amp;amp;table_a"&lt;BR /&gt;
    ;&lt;BR /&gt;
&lt;BR /&gt;
alter table &amp;amp;table_b &lt;BR /&gt;
  modify &amp;amp;change  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%alter&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp</description>
      <pubDate>Mon, 25 Apr 2011 11:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48195#M9943</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-25T11:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48196#M9944</link>
      <description>Hi&lt;BR /&gt;
A similar approach but without the need to re-write the table.&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
   attrib &lt;BR /&gt;
      key label='this is the key &amp;amp; nothing else'&lt;BR /&gt;
      a format=8. label='test &amp;amp; test';&lt;BR /&gt;
   do key=1 to 5;&lt;BR /&gt;
      a=1;&lt;BR /&gt;
      b='abc';&lt;BR /&gt;
      c=1;&lt;BR /&gt;
      output;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data b;&lt;BR /&gt;
   do key=6 to 10;&lt;BR /&gt;
      a=1; &lt;BR /&gt;
      b='abcd';&lt;BR /&gt;
      d=5;&lt;BR /&gt;
      output;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%let rename=;&lt;BR /&gt;
%let assign=;&lt;BR /&gt;
%let length=;&lt;BR /&gt;
%let drop=;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
   select &lt;BR /&gt;
      cats(BASE.name,'=xyz_',BASE.varnum)&lt;BR /&gt;
&lt;BR /&gt;
     ,cats(BASE.name,'=xyz_',BASE.varnum,';')&lt;BR /&gt;
&lt;BR /&gt;
     ,case&lt;BR /&gt;
         when BASE.type='char' then&lt;BR /&gt;
               catx(' ',BASE.name,cats('length=$',BASE.length))&lt;BR /&gt;
         else  catx(' ',BASE.name,cats('length=',BASE.length))&lt;BR /&gt;
         end&lt;BR /&gt;
&lt;BR /&gt;
     ,cats('drop xyz_',BASE.varnum,';')&lt;BR /&gt;
&lt;BR /&gt;
     into  :rename separated by ' '&lt;BR /&gt;
         , :assign separated by ' '&lt;BR /&gt;
         , :length separated by ' '&lt;BR /&gt;
         , :drop   separated by ' '&lt;BR /&gt;
&lt;BR /&gt;
   from dictionary.columns BASE, dictionary.columns DATA&lt;BR /&gt;
&lt;BR /&gt;
   where upcase(BASE.name)=upcase(DATA.name)&lt;BR /&gt;
         and base.length ne data.length&lt;BR /&gt;
         and BASE.libname='WORK' and BASE.memname='A'&lt;BR /&gt;
         and DATA.libname='WORK' and DATA.memname='B'&lt;BR /&gt;
&lt;BR /&gt;
   order by BASE.varnum&lt;BR /&gt;
   ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%put rename:  &amp;amp;rename;&lt;BR /&gt;
%put assign:  &amp;amp;assign;&lt;BR /&gt;
%put length:  &amp;amp;length;&lt;BR /&gt;
%put drop:    &amp;amp;drop;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data V_B / view=V_B;&lt;BR /&gt;
   set B(rename=(&amp;amp;rename));&lt;BR /&gt;
   attrib &amp;amp;length;&lt;BR /&gt;
   &amp;amp;assign&lt;BR /&gt;
   &amp;amp;drop&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc append base=A data=V_B force nowarn;&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 26 Apr 2011 04:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48196#M9944</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-26T04:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48197#M9945</link>
      <description>Hi.Patrick&lt;BR /&gt;
My code is also not to re-write dataset, it is directly to modify the attribute of variables.&lt;BR /&gt;
It is good to see you for a long time not to see your post.&lt;BR /&gt;
Is it still too busy to post?&lt;BR /&gt;
&lt;BR /&gt;
Cheers &lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 26 Apr 2011 09:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48197#M9945</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-26T09:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48198#M9946</link>
      <description>Hi Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Yes, unfortunately (?) I've been really busy lately.&lt;BR /&gt;
&lt;BR /&gt;
And: I still think that changing the length of a variable needs re-creating the SAS file.&lt;BR /&gt;
&lt;BR /&gt;
Length is not a simple variable attribute like a format or a label. I assume that's also the reason why you can't change it with Proc Datasets the way you change other attributes.&lt;BR /&gt;
&lt;BR /&gt;
Considering that SAS stores data rectangular the SAS file must be re-created in order to change the variable length (a view kind of also re-creates the table in memory).&lt;BR /&gt;
&lt;BR /&gt;
Just run the following code and compare the file size of test1 and test2 and you will see:&lt;BR /&gt;
&lt;BR /&gt;
options compress=no;&lt;BR /&gt;
&lt;BR /&gt;
libname test 'c:\temp';&lt;BR /&gt;
&lt;BR /&gt;
data test.test1 test.test2;&lt;BR /&gt;
  length var $ 10;&lt;BR /&gt;
  do i=1 to 1000;&lt;BR /&gt;
    var=put(i,8.);&lt;BR /&gt;
    output test.test1;&lt;BR /&gt;
    output test.test2;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  alter table test.test2&lt;BR /&gt;
    modify var char(1000);&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick

Message was edited by: Patrick</description>
      <pubDate>Wed, 27 Apr 2011 08:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48198#M9946</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-27T08:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48199#M9947</link>
      <description>nothing seems to solve this so far, so:&lt;BR /&gt;
data B ;&lt;BR /&gt;
* load B with the type+length attributes of A  ;&lt;BR /&gt;
 if 0 then set A ;&lt;BR /&gt;
* this will load ALL columns of A as well (not just those in B) ;&lt;BR /&gt;
 &lt;BR /&gt;
* load values from B ;&lt;BR /&gt;
 set B ;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
* and add B records to A;&lt;BR /&gt;
proc append base= A data= B force ;&lt;BR /&gt;
run;&lt;BR /&gt;
The data step reloading B, will get error[pre] &lt;BR /&gt;
ERROR: Variable XXXXXXX has been defined as both character and numeric[/pre] if you have a variable on A and B with different types.&lt;BR /&gt;
&lt;BR /&gt;
Character data in B will truncate if A lengths are not wide enough to hold B strings!&lt;BR /&gt;
&lt;BR /&gt;
Similarly, if numeric columns in A have shorter (stored) lengths than corresponding columns in B, numeric precision will be affected!&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
&lt;B&gt;CBSXB&lt;/B&gt; &lt;BR /&gt;
To avoid the "ERROR"-condition above, &lt;B&gt;what are your rules&lt;/B&gt; for conversion between character and numeric data types?&lt;BR /&gt;
Do you need special handling when $lengths in A are not wide enough for corresponding columns in A?&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 27 Apr 2011 08:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48199#M9947</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-27T08:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48200#M9948</link>
      <description>Hi Peter&lt;BR /&gt;
&lt;BR /&gt;
I was very aware that the code I suggested doesn't handle character/numeric missmatch - and it's on purpose that my code will throw an error for such a case(enough is enough...).&lt;BR /&gt;
&lt;BR /&gt;
Also on purpose I've set up the example in a way that strings get truncated - just to show that may be modifying variable lengths is not really the solution to the problem.&lt;BR /&gt;
&lt;BR /&gt;
I believe what one should do is to define appropriate variable lengths explicitly (attrib statement) so length matching issues won't occur at all.&lt;BR /&gt;
&lt;BR /&gt;
The amendment to the code I've posted could be to compare variable lengths between base and transaction data set and change the length in the data set where it's shorter.&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
      <pubDate>Wed, 27 Apr 2011 11:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48200#M9948</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-27T11:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48201#M9949</link>
      <description>Patrick &lt;BR /&gt;
It's easy to agree with you. &lt;BR /&gt;
I might go further than enter a sensible policy discussion. &lt;BR /&gt;
The original poster requested techniques to solve what looks like a real problem when generalised. However, we don't know enough about the environment of the problem - perhaps it is simpler than the original question implies (to us). &lt;BR /&gt;
It would be good to hear more from that poster. &lt;BR /&gt;
 &lt;BR /&gt;
Regards&lt;BR /&gt;
Peter</description>
      <pubDate>Wed, 27 Apr 2011 14:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48201#M9949</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-27T14:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48202#M9950</link>
      <description>Hi.&lt;BR /&gt;
Patrick.&lt;BR /&gt;
I also notice this interesting thing that proc datasets can not change the length of variable,&lt;BR /&gt;
But proc sql can do really,Is it strange?.&lt;BR /&gt;
If you use proc contents or see the attribute of dataset ,then you will see the length of variable is really change after sql.&lt;BR /&gt;
But data new; set old; attrib ...; will really load dataset once ,it yields to low efficient.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Thu, 28 Apr 2011 00:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48202#M9950</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-28T00:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48203#M9951</link>
      <description>Dear Peter:&lt;BR /&gt;
 I also think the biggest challenge is to change variable type between two tables.&lt;BR /&gt;
So, I think it might will be more easy that firstly changing all the variables type into character, after proc append then change the variable type which is numeric originally in dataset A. How do you think?&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
Cheers from BeiJing ,China</description>
      <pubDate>Thu, 28 Apr 2011 00:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48203#M9951</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-28T00:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48204#M9952</link>
      <description>Hi Ksharp&lt;BR /&gt;
&lt;BR /&gt;
But this is exactly the point: Also SQL alter table must re-create the SAS file.&lt;BR /&gt;
&lt;BR /&gt;
Length is just more than only a simple variable attribute in the descripter part. The length directly connects to how data gets stored - so changing the length just must result in re-writing the data part whatever SAS syntax is used.&lt;BR /&gt;
&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 28 Apr 2011 10:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48204#M9952</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-28T10:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48205#M9953</link>
      <description>interesting thought occurs.&lt;BR /&gt;
 &lt;BR /&gt;
SAS stores data as we request it (having requested formats, lengths, compression, etc.).&lt;BR /&gt;
 &lt;BR /&gt;
to be used in a PROC or a data step, short length numerics are expanded to length 8. When we request compression, the storage must be expanded to be used. &lt;BR /&gt;
 &lt;BR /&gt;
New string lengths, could "be requested".&lt;BR /&gt;
It would be similar to "requesting a new column order". &lt;BR /&gt;
No data moves (except in data set header) until the data portion is actually used.&lt;BR /&gt;
The original data would not be affected - just new data derived from the old data would be subject also to these "requests"&lt;BR /&gt;
These "requests" could be made with PROC DATASETS.&lt;BR /&gt;
 &lt;BR /&gt;
well that is just in my imagination - it is not what happens - as we know it for real!&lt;BR /&gt;
  &lt;BR /&gt;
peterC

SAS already achieves this and more! The technology is not in PROC DATASETS - it's referred to as DATA set VIEW!&lt;BR /&gt;
very little not already built in! &lt;BR /&gt;
peterC 07:55 29-Apr-11.        &lt;BR /&gt;
Message was edited by: Peter.C</description>
      <pubDate>Thu, 28 Apr 2011 19:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48205#M9953</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-04-28T19:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48206#M9954</link>
      <description>Hi.Patrick.&lt;BR /&gt;
It looks like You have more insight than me .But I have not found something about it in documentation. Education!&lt;BR /&gt;
:)&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 29 Apr 2011 01:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/48206#M9954</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-29T01:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/395953#M95565</link>
      <description>&lt;P&gt;This scenario is described in a blog post&amp;nbsp;&lt;A title="Changeing variable attribute" href="http://blogs.sas.com/content/sgf/2017/03/28/changing-variable-type-and-variable-length-in-sas-datasets/" target="_blank"&gt;Changing variable type and variable length in SAS datasets&lt;/A&gt; where you can find SAS code example on how to change variable attributes of a SAS data table such as type and length. It seems to be a common problem when appending SAS data tables with slighty different column attributes.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 15:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/395953#M95565</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2017-09-14T15:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: automatic update of variable attributes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/396086#M95586</link>
      <description>&lt;P&gt;This is a non-trivial problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note.1: where I changed the length of a known variable with the attribute statement&lt;/P&gt;&lt;P&gt;and the var-name does not match the case of the master data set&lt;/P&gt;&lt;P&gt;then that var-name is changed.&lt;/P&gt;&lt;P&gt;Since is this is a demo of proof-of-concept&lt;/P&gt;&lt;P&gt;this may not matter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note.2 be aware of the fragile nature of the cat* functions;&lt;/P&gt;&lt;P&gt;if they return a value larger than $200 then it will truncate your list&lt;/P&gt;&lt;P&gt;solution: add a length=nnnn after the catx function call&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note.3 data structure may be only &amp;lt;1% of your code&lt;/P&gt;&lt;P&gt;but it is the first place I turn to when my algorithm fails.&lt;/P&gt;&lt;P&gt;Likewise here: I recommend adding the data structure of A&lt;/P&gt;&lt;P&gt;to the code that creates B; this is my recommended solution and solves all later appending.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA B;
if 0 then set A;
*...;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;note.4 this solution assumes both data sets are different&lt;/P&gt;&lt;P&gt;and thus have to be copied in order to change the lengths.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hth&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; list processing maven&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*note case of name matters in output;
data class1;
     attrib sex length = $2;
set sashelp.class;

data class2;
     attrib name length = $10;
set sashelp.class;

%macro save_attrib(libname=work, memname=,out=);
PROC sql noprint;
         create table &amp;amp;out as
         select name, lowcase(name) as name_lc, type, length
         from dictionary.columns
         where libname eq "%upcase(&amp;amp;libname)"
           and memname eq "%upcase(&amp;amp;memname)"
           and memtype eq "DATA";
         quit;
run;
%mend;
%save_attrib(memname=class1,out=contents1)
%save_attrib(memname=class2,out=contents2)

DATA attributes;
set contents1
    contents2;
run;
PROC sort data = &amp;amp;syslast;
          by name_lc length;
run;
DATA attributes;
     retain max_length 0;
set  &amp;amp;syslast;
by   name_lc;
if first.name_lc then max_length = 0;
max_length = max(max_length,length);
if last.name_lc then output;
run;
PROC sql noprint;
         select catx(' ',name,'length='
         ,case when type eq 'char' then '$'
               else                     ' '
               end
         ,length) into :list separated by ' '
         from &amp;amp;syslast;
         quit;
%put echo &amp;amp;=list;
%macro update_attrib(data=,base=largest);
DATA &amp;amp;DATA;
     attrib &amp;amp;list;
set &amp;amp;data;
PROC append data = &amp;amp;data
            base = &amp;amp;base;
run;
%mend;
%update_attrib(data=class1)
%update_attrib(data=class2)

proc print data = &amp;amp;syslast;

PROC sql; describe table &amp;amp;syslast;
          quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 20:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/automatic-update-of-variable-attributes/m-p/396086#M95586</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2017-09-14T20:16:05Z</dc:date>
    </item>
  </channel>
</rss>

