<?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: Data Truncation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368123#M87755</link>
    <description>They can be identified with suffix _new.&lt;BR /&gt;They are all in the same dataset.</description>
    <pubDate>Mon, 19 Jun 2017 00:54:49 GMT</pubDate>
    <dc:creator>SASPhile</dc:creator>
    <dc:date>2017-06-19T00:54:49Z</dc:date>
    <item>
      <title>Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368116#M87752</link>
      <description>&lt;P&gt;&lt;BR /&gt;The default lengths (the dataset has all character variables)while importing to SAS datasets for all the variables is 100. Later part of the data processing, the lengths of variables are assigned.&lt;BR /&gt;Now I would like to compare if data is truncated due to new length. and if so, i would want the row number, old value and truncated value saved in dataset.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;for example, the default length for varaible pharma_outlet is 100 and it has the following two values.&lt;/P&gt;&lt;P&gt;mckefsson patient care solutions&lt;BR /&gt;mckefsson patient care solutions &amp;amp; medical equipment &amp;amp; devices&lt;/P&gt;&lt;P&gt;The new assigned length is 50.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;pharma_outlet&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;pharma_outlet_new&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mckefsson patient care solutions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;mckefsson patient care solutions&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mckefsson patient care solutions &amp;amp; medical equipment &amp;amp; devices&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;mckefsson patient care solutions &amp;amp; medical equipm&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from the above, the second record is truncated.&lt;BR /&gt;How to output, the second record and its row number?&lt;/P&gt;&lt;P&gt;The datasets have 50 variables and it will be cumbersome to compare old and new column names.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 00:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368116#M87752</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-19T00:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368120#M87753</link>
      <description>&lt;P&gt;Try using PROC COMPARE. It will list variables with unequal values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 00:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368120#M87753</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-19T00:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368122#M87754</link>
      <description>&lt;P&gt;Do you have a systematic way of knowing the new and old variable names?&lt;/P&gt;
&lt;P&gt;Are they in the same dataset? Or different datasets? If different, multiple different datasets or one?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're probably looking at a macro, but I would also recommend starting with PROC COMPARE. Note that&amp;nbsp;you can specify which variables need to be compared.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 00:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368122#M87754</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-19T00:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368123#M87755</link>
      <description>They can be identified with suffix _new.&lt;BR /&gt;They are all in the same dataset.</description>
      <pubDate>Mon, 19 Jun 2017 00:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368123#M87755</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-19T00:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368125#M87756</link>
      <description>&lt;P&gt;i started using complev and I really like , it will help you understand how much difference your current variable value to new value. But your purpose i think below query may work for most of sceanerios. if they are same table then use same name for both tables and change variable names.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have1;
infile datalines truncover;
informat var1 $100.;
input var1 $100.;
datalines;
pharma_outlet                                                              
mckefsson patient care solutions
mckefsson patient care solutions &amp;amp; medical equipment &amp;amp; devices 
;
data have2;
informat var1 $50.;
input var1 $50.;
datalines;
pharma_outlet                                                              
mckefsson patient care solutions
mckefsson patient care solutions &amp;amp; medical equipment &amp;amp; devices 
;

proc sql;

select a.var1 as original,
       b.var1 as truncatedvalue     
  from have1 a
  inner join have2 b
  on b.var1 = substr(a.var1,1,50) 
  and a.var1 ne b.var1;

quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 01:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368125#M87756</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-19T01:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368126#M87757</link>
      <description>There are no have1 and have2 , there's only one dataset.</description>
      <pubDate>Mon, 19 Jun 2017 01:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368126#M87757</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-19T01:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368127#M87758</link>
      <description>&lt;P&gt;then something like this&lt;/P&gt;
&lt;PRE&gt;proc sql;

select a.var1 as original,
       b.var_new as truncatedvalue     
  from have a
  inner join have b
  on b.var_new = substr(a.var1,1,50) 
  and a.var1 ne b.var_new;

quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 01:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368127#M87758</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-19T01:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368129#M87759</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

truncated = 0;

if varName ne varName_New then truncated = 1; 

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 01:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368129#M87759</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-19T01:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368130#M87760</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array old_names (*) $ &amp;lt;list of old variables here&amp;gt;;
array new_names(*) $ &amp;lt;list of new variables here&amp;gt;;

array flag(*) flag1 - flag50 (50*0); *number of variables here should be specified - note they are initialized to zero for every line;

do i=1 to dim(old_names);
if old_names(i) ne new_names(i) then flag(i) = 1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 01:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368130#M87760</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-19T01:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368131#M87761</link>
      <description>As I said there are 50 old variables and 50 new variables. To distinguish&lt;BR /&gt;between them, the new variable has suffix _new.&lt;BR /&gt;Thinking about data step as it gives flexibility of arrays. But don't know&lt;BR /&gt;how to create arrays one for old and one for new.</description>
      <pubDate>Mon, 19 Jun 2017 01:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368131#M87761</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-19T01:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368132#M87762</link>
      <description>&lt;P&gt;aha, i missed that part&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 01:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368132#M87762</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-19T01:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368156#M87770</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Code was edited to fulfill your new query&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"I would want to kep only those variables from old_names and new_varaibles that satisfies the condition old_flag(i) = '1';&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;say for instance old_name(1) is disease and if the new length and old length of disease dont match then old_flag=1.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;so i want to keep only disease_old and disease_new varaibles".&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming each old variable VAR has its VAR_NEW you can try next code.&lt;/P&gt;
&lt;P&gt;Addapt 3 macro variables at top:&lt;/P&gt;
&lt;PRE&gt;%let lib=work; /* adapt library name */&lt;BR /&gt;%let dsn=test; /* adapt dataset name */&lt;BR /&gt;%let key="key"; /* adapt list of key variables: "key1" "key2" etc. */&lt;BR /&gt;&lt;BR /&gt;/**** For TEST only - start ***/&lt;BR /&gt;data test;&lt;BR /&gt; key = 'KEY';&lt;BR /&gt; varx = 'Short text';&lt;BR /&gt; varx_new = 'Short text replaced with long one';&lt;BR /&gt; output;&lt;BR /&gt;run;&lt;BR /&gt;/**** For TEST - end ***/&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt; create table vars as select name&lt;BR /&gt; from dictionary.columns&lt;BR /&gt; where libname=upcase("&amp;amp;lib") and &lt;BR /&gt; memname=upcase("&amp;amp;dsn") &lt;BR /&gt; order by name;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;filename pgm '/folders/myshortcuts/My_Folders/flat/temp.sas';&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt; set vars end=eof;&lt;BR /&gt; file pgm;&lt;BR /&gt; if _N_=1 then do;&lt;BR /&gt; put 'data want;';&lt;BR /&gt; put "set &amp;amp;lib..&amp;amp;dsn;";&lt;BR /&gt; end;&lt;BR /&gt; name = lowcase(name); &lt;BR /&gt; if name not in (&amp;amp;key) and&lt;BR /&gt; index(name,'_new') = 0&lt;BR /&gt; then do;&lt;BR /&gt; a_line = 'if '||strip(name)|| ' NE '||strip(name)||'_new;';  /* truncated text */&lt;BR /&gt; put a_line;&lt;BR /&gt; end;&lt;BR /&gt; if eof then put 'RUN;';&lt;BR /&gt;run;&lt;BR /&gt;%include pgm /source2; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;The code creates a program as a temporary file and then INCLUDEs it.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 20:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368156#M87770</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-19T20:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368466#M87883</link>
      <description>&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;BR /&gt;array old_names(*) $ &amp;amp;old_names;&lt;BR /&gt;array new_names(*) $ &amp;amp;tgt_names;&lt;BR /&gt;array old_flag(*) $ &amp;amp;old_flags;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;do i=1 to dim(old_names);&lt;BR /&gt;if length(old_names(i)) ne length(new_names(i)) then old_flag(i) = '1';&lt;BR /&gt;else old_flag(i)='0';&lt;BR /&gt;if old_flag(i) = '1' then output;&lt;BR /&gt;-----Keep Statement logic-----&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would want to kep only those variables from old_names and new_varaibles that satisfies the condition old_flag(i) = '1';&lt;/P&gt;&lt;P&gt;say for instance old_name(1) is disease and if the new length and old length of disease dont match then old_flag=1.&lt;BR /&gt;so i want to keep only disease_old and disease_new varaibles,&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 19:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368466#M87883</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-19T19:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368486#M87893</link>
      <description>&lt;P&gt;Keep/Drop are not conditional statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll need to process the entire file, then summarize the flags to determine which variables need to be kept or not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This solution, provided, answers your initial question (below), there was no mention of keep/dropping variables. At any rate, you need to summarize the flags to see if all are 0/1 and then any that have a 1 are added to your list of drop/keep which woud happen in a next step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;SPAN&gt;Now I would like to compare if data is truncated due to new length. and if so, i would want the row number, old value and truncated value saved in dataset.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 20:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368486#M87893</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-19T20:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Data Truncation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368492#M87896</link>
      <description>&lt;P&gt;Use PROC COMPARE. &amp;nbsp;You can get the list of variables by getting reading the contents.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input var1 $80. ;
  length new_var1 $50 ;
  new_var1=var1;
  x=1;
cards4;
mckefsson patient care solutions                                                    
mckefsson patient care solutions &amp;amp; medical equipment &amp;amp; devices
;;;;

proc contents data=have out=contents noprint;
run;

proc sql ;
  select a.name,b.name 
    into :orig separated by ' '
       , :new  separated by ' '
    from contents a 
       , contents b
    where upcase('NEW_'||a.name) = upcase(b.name)
  ;
quit;

proc compare data=have ;
  var &amp;amp;orig ;
  with &amp;amp;new ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jun 2017 21:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Truncation/m-p/368492#M87896</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-19T21:02:06Z</dc:date>
    </item>
  </channel>
</rss>

