<?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: Choose maximum variable length with set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323808#M71827</link>
    <description>&lt;P&gt;Not an option, but you could write some code (e.g., using proc sql to get the max length for each variable by comparing the values in dictionary.columns and have proc sql create a macro variable that includes entries like "length variablename x;"), run that code before running your current code, and include the macro variable before your set statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jan 2017 22:59:56 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-01-10T22:59:56Z</dc:date>
    <item>
      <title>Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323794#M71818</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets which the same variables but differing lengths. &amp;nbsp;I am using a set statement to combine them. &amp;nbsp;Is there any way for SAS to pick the maximum length for each variable in the new dataset rather than just picking the length of the variable from the first set dataset listed? &amp;nbsp;There are numerous variables, and the lengths will not be consistent nor one set consistently longer than the others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, on one day, the length of ID might be 6 in the first dataset and 8 in the second, but on the next day it might be 9 in the first dataset and 5 in the second.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to avoid having to scan the datasets each time and pick out the maximum. &amp;nbsp;Is there any option in the set statement to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 21:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323794#M71818</guid>
      <dc:creator>Kastchei</dc:creator>
      <dc:date>2017-01-10T21:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323800#M71823</link>
      <description>&lt;P&gt;I don't think so.&lt;/P&gt;
&lt;P&gt;Is it possible to standardize your process ahead of time, ensure the data is read in a standard manner?&lt;/P&gt;
&lt;P&gt;Or create a master dataset with the maximum lengths and variables definitions that are standard? Then you can use that each time as the 'master' data and it will set the lengths.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 22:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323800#M71823</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-10T22:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323808#M71827</link>
      <description>&lt;P&gt;Not an option, but you could write some code (e.g., using proc sql to get the max length for each variable by comparing the values in dictionary.columns and have proc sql create a macro variable that includes entries like "length variablename x;"), run that code before running your current code, and include the macro variable before your set statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 22:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323808#M71827</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-01-10T22:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323818#M71832</link>
      <description>&lt;P&gt;The approach to expand slightly on &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;'s is to include one or more Length statements before the SET statement with the desired length.&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length thisvar $ 25;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set data1 data2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;would set the length of the variable Thisvar to 25 characters regardless of which set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are going to be combining these data sets, or others similar then I suggest going back further into your process and determine why these variables are different lengths, especially the data structure and contents is otherwise the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using data that is brought into SAS using Proc Import, a frequent cause of mismatched length,&amp;nbsp;then you might consider a different approach for bringing the data into SAS. Another method would be to create a data set with the appropriate characteristics for all of the variables involved that has no observations. Then make that the first data set listed in the datasets on the set statement.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 23:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323818#M71832</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-10T23:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323820#M71834</link>
      <description>&lt;P&gt;If both tables have the same variables then a Proc SQL Union does what you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  set sashelp.class;
run;

data have2;
  length sex $5;
  set sashelp.class;
run;

proc sql;
  create table want as
  select * from have1
  union corr all
  select * from have2
  ;
quit;

proc contents data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that's an ongoing issue for a defined table structure then another option would be to create an empty "mapping" dataset with defined variable attributes (so with all the max. lengths you can reasonably expect) and then use this mapping dataset first in a set statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class_mapping;
  length sex $5;
  set sashelp.class;
  stop;
run;

data want2;
  set class_mapping sashelp.class;
run;

proc contents data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jan 2017 23:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323820#M71834</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-10T23:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323868#M71848</link>
      <description>&lt;P&gt;You are dealing with symptoms, but not with the root cause. The root cause is a flawed import process, probably using proc import.&lt;/P&gt;
&lt;P&gt;Change to explicitly written data steps to read external data, and use the description provided by the data provider(s) as a base.&lt;/P&gt;
&lt;P&gt;The improperly imported datasets can be fixed by one of the methods suggested.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 07:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/323868#M71848</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-11T07:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Choose maximum variable length with set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/325813#M72501</link>
      <description>&lt;P&gt;Thanks everyone. &amp;nbsp;I like this SQL solution as it's simple code, should work fairly quickly, and doesn't require any assumptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, unfortunately, I am not permitted to standardize the inputs (clueless bosses...).&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 21:33:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choose-maximum-variable-length-with-set/m-p/325813#M72501</guid>
      <dc:creator>Kastchei</dc:creator>
      <dc:date>2017-01-18T21:33:57Z</dc:date>
    </item>
  </channel>
</rss>

