<?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: Variable Name as value in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/370214#M11180</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;A bit better prepared sample data and desired output would be appreciated - but here you go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.have(drop=_:);
  INFILE DATALINES4
    DLM='7F'x
    MISSOVER
    DSD;
  INPUT
    company_name     : $10.
    business_description : $30.
    _business_description2 : $30.
    business_Address : $40.
    _business_Address2 : $40.;
  output;
  business_description=_business_description2;
  business_Address=_business_Address2;
  output;
  DATALINES4;
Byrum&amp;#127;GH Utilization&amp;amp;IV Solutions&amp;#127;GH Utilization&amp;amp;IV&amp;#127;P.O.BOX 5523,Kryton,TN 38172-2468&amp;#127;P.O.BOX 5523,Kryton,TN 38172-2468
ICORE&amp;#127;Novo Distribution&amp;#127;Novo Distribution&amp;#127;P.O.BOX 5523,Kryton,TN 38172-2468&amp;#127;P.O.BOX 5523,Kryton,TN 38172
;;;;
run;

proc sort data=have;
  by company_name;
run;

data want(keep=obs_num company_name variable_name max_string trunc_string);

  length obs_num 8;
  if 0 then set have;
  length Variable_Name $32 max_string trunc_string $100.;

  array test {2} business_description business_Address;
  array _max_len [2] 8 _temporary_;
  array _max_str [2] $100 _temporary_;

  /* determine longest string per company and variable */
  do while(1);
    set have;
    by company_name;
    do _i=1 to dim(test);
      if first.company_name or lengthn(test[_i])&amp;gt;_max_len[_i] then
        do;
          _max_len[_i]=lengthn(test[_i]);
          _max_str[_i]=test[_i];
        end;
    end;
    if last.company_name then leave;
  end;

  /* DQ: output cases with truncated strings */
  do while(1);
    set have end=last;
    by company_name;
    obs_num+1;
    do _i= 1 to dim(test);
      if lengthn(test[_i])&amp;lt;_max_len[_i] then
        do;
          variable_name=vname(test[_i]);
          max_string=_max_str[_i];
          trunc_string=test[_i];
        end;
    end;
    if last.company_name then leave;
  end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9821iE554A07919FE5DD4/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.JPG" title="Capture.JPG" /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 24 Jun 2017 03:19:19 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-06-24T03:19:19Z</dc:date>
    <item>
      <title>Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369849#M11167</link>
      <description>&lt;P&gt;Sample data is attached:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to create a dataset that contains the variable as value ,its origibal value and truncated values as shown below:&lt;/P&gt;&lt;P&gt;In the first record, business_name is truncated for company name "Byrum". The lengths of business_name and new_business_names are different and their values are also truncated.&lt;BR /&gt;In the recond row, the address got truncated for "ICORE".&lt;/P&gt;&lt;P&gt;I would like to show them in a dataset as following:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;company_name&lt;/TD&gt;&lt;TD&gt;variable&lt;/TD&gt;&lt;TD&gt;Original_value&lt;/TD&gt;&lt;TD&gt;truncated_value&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Byrum&lt;/TD&gt;&lt;TD&gt;business_description&lt;/TD&gt;&lt;TD&gt;GH Utilization&amp;amp;IV Solutions&lt;/TD&gt;&lt;TD&gt;GH Utilization&amp;amp;IV&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ICORE&lt;/TD&gt;&lt;TD&gt;business_Address&lt;/TD&gt;&lt;TD&gt;P.O.BOX 5523,Kryton,TN 38172-2468&lt;/TD&gt;&lt;TD&gt;P.O.BOX 5523,Kryton,TN 38172&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset can have 100's of variables with original and truncated values. I want to compare only those variables there is a truncation in their values.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 12:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369849#M11167</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-23T12:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369851#M11168</link>
      <description>&lt;P&gt;What is the question that you want answered?&lt;/P&gt;
&lt;P&gt;Do you want to find the observations where the truncated_value is different?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  where truncated_value ne original_value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jun 2017 12:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369851#M11168</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-23T12:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369857#M11170</link>
      <description>&lt;P&gt;Its been mentioned before, please don't post Office files as they are security risk. &amp;nbsp;To get a good answer, post test data in the form of a datastep, what the output should look like, and explain any logic between the two.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 13:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369857#M11170</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-23T13:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369875#M11171</link>
      <description>&lt;P&gt;It is ficticious data!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 13:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369875#M11171</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-23T13:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369878#M11172</link>
      <description>&lt;P&gt;It does not matter, Office files are a security risk, some even block these files. &amp;nbsp;Not to mention the extra work responders would need to do to import that file, guess what the structure is etc. &amp;nbsp;Please follow the folowing post on how to provide test data as a datastep in the body of the post (using the {i} button):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 13:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369878#M11172</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-23T13:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369891#M11173</link>
      <description>&lt;P&gt;Sure!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 14:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/369891#M11173</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-23T14:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/370214#M11180</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;A bit better prepared sample data and desired output would be appreciated - but here you go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.have(drop=_:);
  INFILE DATALINES4
    DLM='7F'x
    MISSOVER
    DSD;
  INPUT
    company_name     : $10.
    business_description : $30.
    _business_description2 : $30.
    business_Address : $40.
    _business_Address2 : $40.;
  output;
  business_description=_business_description2;
  business_Address=_business_Address2;
  output;
  DATALINES4;
Byrum&amp;#127;GH Utilization&amp;amp;IV Solutions&amp;#127;GH Utilization&amp;amp;IV&amp;#127;P.O.BOX 5523,Kryton,TN 38172-2468&amp;#127;P.O.BOX 5523,Kryton,TN 38172-2468
ICORE&amp;#127;Novo Distribution&amp;#127;Novo Distribution&amp;#127;P.O.BOX 5523,Kryton,TN 38172-2468&amp;#127;P.O.BOX 5523,Kryton,TN 38172
;;;;
run;

proc sort data=have;
  by company_name;
run;

data want(keep=obs_num company_name variable_name max_string trunc_string);

  length obs_num 8;
  if 0 then set have;
  length Variable_Name $32 max_string trunc_string $100.;

  array test {2} business_description business_Address;
  array _max_len [2] 8 _temporary_;
  array _max_str [2] $100 _temporary_;

  /* determine longest string per company and variable */
  do while(1);
    set have;
    by company_name;
    do _i=1 to dim(test);
      if first.company_name or lengthn(test[_i])&amp;gt;_max_len[_i] then
        do;
          _max_len[_i]=lengthn(test[_i]);
          _max_str[_i]=test[_i];
        end;
    end;
    if last.company_name then leave;
  end;

  /* DQ: output cases with truncated strings */
  do while(1);
    set have end=last;
    by company_name;
    obs_num+1;
    do _i= 1 to dim(test);
      if lengthn(test[_i])&amp;lt;_max_len[_i] then
        do;
          variable_name=vname(test[_i]);
          max_string=_max_str[_i];
          trunc_string=test[_i];
        end;
    end;
    if last.company_name then leave;
  end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9821iE554A07919FE5DD4/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.JPG" title="Capture.JPG" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 03:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/370214#M11180</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-24T03:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Variable Name as value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/370947#M11225</link>
      <description>I'm seeing empty columns for variable_name max_string and trunc_string&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Tue, 27 Jun 2017 14:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Variable-Name-as-value/m-p/370947#M11225</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-06-27T14:15:39Z</dc:date>
    </item>
  </channel>
</rss>

