<?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: lenght of variables while combining datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384102#M91663</link>
    <description>&lt;P&gt;Then what you should actually do, is define your process better with fixed lengths for your values. You should know what the maximums will be and create a table as that structure. Then insert the records into that table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solutions provided, scan all tables and take the longest length assigned. This is in line with how your question is posed. Actually scanning each record every time is inefficient. It's better to understand your data and make the limits based on your knowledge of the process rather than building it based on what you see in the data currently.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 30 Jul 2017 21:04:35 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-07-30T21:04:35Z</dc:date>
    <item>
      <title>lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384071#M91648</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a library let's say 'library1'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this library i have datasets with &amp;nbsp;the same variables (names, type, etc.) Every dataset is created at the end of the month, so i have for example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset_201701&lt;/P&gt;&lt;P&gt;dataset_201702&lt;/P&gt;&lt;P&gt;dataset_201703&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, datasets have the same variables, but they could have have different lenghts of observations which can cause unexpected results while combining them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset_201701 has an observation in variable 'abc' which has lenght of 50 .&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset_201702 has an observation in variable 'abc' which has lenght of 40.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if someone combines these datasets&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combine;&lt;/P&gt;&lt;P&gt;set dataset_201701 dataset_201702;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will truncate the variable abc to 40.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the question is: How can I check the longest observation in every variable, in every dataset in my library 'library1' and set the lenght for the longest observation ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basing on my example I want the variable abc to have lenght of 50 in every dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 15:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384071#M91648</guid>
      <dc:creator>John1231</dc:creator>
      <dc:date>2017-07-30T15:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384072#M91649</link>
      <description>&lt;P&gt;Get the lengths from SASHELP.VCOLUMN and isolate the maximum values. Then create a LENGTH statement from those values,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
Create table length as
Select name, max(length) as max_length 
From SASHELP.volumns where libname='LIBRARY1'
Group name;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 15:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384072#M91649</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-30T15:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384076#M91650</link>
      <description>&lt;P&gt;You can use &amp;nbsp;- proc sql; select distionary.columns ... - or - sashelp.vcolomn&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in order to create a LENGTH statement with max length of char variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= sashelp.vcolumn (where=(libname='LIBRARY1' and 
                         substr(memname(1,7) = 'DATASET' and type='char' ))
               out=char_vars; by name descending length;
run;

data _null_;
  set char_vars end=eof;
   by name;
        length len_stmt $100;  /* addapt to max length needed */
        retain len_stmt  'length ';

       if eof then call symput('len', trim(len_stmt));

        if first.name;
        len_stmt = catx(' ',len_stmt, strip(varnmae) , strip(length));
run;

data want;
     &amp;amp;len.;   /* line was editted to eliminate double LENGTH keyword */
 set dataset_201701  dataset_201702 ... ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 19:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384076#M91650</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-30T19:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384096#M91658</link>
      <description>&lt;P&gt;hey, thank you for your answers but it in not quite what i'm looking for...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the main task is to&lt;/P&gt;&lt;P&gt;1 check the longest observation in every data set for each variable&lt;/P&gt;&lt;P&gt;2 change the length for each variable in whole library to the length of the longest variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i want to do this each time a new dataset is created (every month), not during combination of sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset 01&lt;/P&gt;&lt;P&gt;variable abc is 30&lt;/P&gt;&lt;P&gt;dataset 02&lt;/P&gt;&lt;P&gt;variable abc is 40&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and after running my code the result that i want is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset 01&lt;/P&gt;&lt;P&gt;variable abc is 40&lt;/P&gt;&lt;P&gt;dataset 02&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable abc is 40&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 18:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384096#M91658</guid>
      <dc:creator>John1231</dc:creator>
      <dc:date>2017-07-30T18:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384098#M91660</link>
      <description>&lt;P&gt;To your suggestion - "&lt;SPAN&gt;&amp;nbsp;check the longest observation in every data" - I have some remarks:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- you possibly use OPTION COMPRESS=YES (check by running: proc options) - then observation lebgth is not symptomatic.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- if there are more severeal char variables in a dataset, you cannot conclude which variable to expand.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;sashelp.vcolumn - holds information on all members (datasets) in all libraries, so there is no need to check each dataset.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Taking max(length) as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;or taking the first length when sorted by descending - you shall get the same result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The code I posted relates to your selected library (library1), checks all datasets named with prefix DATASET (names you gave).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The variable NAME is the variable name in the dataset.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I create a macro variable containing the LENGTH statement to use with maximun length of all character variables in those&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;selected datasets.&amp;nbsp;Finally &amp;nbsp;I show hot to use this macro variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can use it any time you need to concatenate datasets OR you can use it to convert your datasets to be all with same&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;definitions of maximum length. Using OPTION COMPRESS=YES will compress data so that you save disk space inspite&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;expanding length of variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In order to convert your dataset to standard max length run:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data library1.dataset_&amp;lt;any month&amp;gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;len;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set &amp;nbsp;library1.dataset_&amp;lt;any month&amp;gt;;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;RUN;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 19:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384098#M91660</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-30T19:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384102#M91663</link>
      <description>&lt;P&gt;Then what you should actually do, is define your process better with fixed lengths for your values. You should know what the maximums will be and create a table as that structure. Then insert the records into that table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solutions provided, scan all tables and take the longest length assigned. This is in line with how your question is posed. Actually scanning each record every time is inefficient. It's better to understand your data and make the limits based on your knowledge of the process rather than building it based on what you see in the data currently.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 21:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384102#M91663</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-30T21:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: lenght of variables while combining datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384110#M91666</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134217"&gt;@John1231&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;already wrote: You should know your data and define the variable attributes upfront. Analyzing and changing the data every single time sounds like a bad idea.&lt;/P&gt;
&lt;P&gt;If your problem is that you're creating monthly data with different variable lengths then combining the data using a PROC SQL UNION will pre-analyse your variable definitions and will take the longest length (=no truncation risk).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table all_months as
    select *
    from dataset_201701
    outer union corr
    select *
    from dataset_201702
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jul 2017 22:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lenght-of-variables-while-combining-datasets/m-p/384110#M91666</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-30T22:05:36Z</dc:date>
    </item>
  </channel>
</rss>

