<?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: Converting variables to character when stacking datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716745#M221560</link>
    <description>&lt;P&gt;Define "different sources".&lt;/P&gt;
&lt;P&gt;If you get your data from separate (business) entities in different formats (e.g. xlsx vs. text), then you should streamline your orocess by setting up agreements with a unified format for data transfer files.&lt;/P&gt;
&lt;P&gt;If it's just multiple files in the same format, then the use of PROC IMPORT is the most likely culprit.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2021 06:47:26 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-02-04T06:47:26Z</dc:date>
    <item>
      <title>Converting variables to character when stacking datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716594#M221494</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to stack datasets on top of each other&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data output;

set dataset1 dataset2 dataset3 dataset4;

run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All these dataset have same column names, but because they are coming from different sources, some of them are numeric where it could be a character in the other one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I tell SAS to stack dataset together but tat the same time convert all variables into character?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Justinas&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 18:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716594#M221494</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2021-02-03T18:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting variables to character when stacking datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716615#M221501</link>
      <description>&lt;P&gt;There is no built in feature that will stack variables of same name but different types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The template for creating a proper target character variable in the stacked result set is to ensure the width (variable length) is wide enough and the numeric variables are transformed with a PUT using the appropriate FORMAT or some other mechanism.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use VVALUE function to retrieve the formatted value of a numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length x $30;
  set 
    source_1 (in=_1)
    source_2 (in=_2 rename=(x=x_num2))
    source_3 (in=_3 rename=(x=x_num3))
  ;

  select;
    when (_1) ; 
    when (_2) x = vvalue(x_num2);
    when (_3) x = vvalue(x_num3);
    otherwise;
  end;

  drop x_num2 x_num3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you understand the coding pattern you can use meta data to compute the source code needed into macro variable(s) that would then be resolved in a skeleton or template DATA step that relies on the macro system resolving the computed source code(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 19:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716615#M221501</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2021-02-03T19:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Converting variables to character when stacking datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716687#M221535</link>
      <description>&lt;P&gt;Are these ID numbers, or other values that will never be subject to mathematical operations (average, sum, ... )?&amp;nbsp; &amp;nbsp;And even if they are ID numbers, consider writing them to character values with leading zeroes, if necessary.&amp;nbsp; Otherwise a different sort order would be produced (i.e. '54' would be greater than '122', but '054' would not).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 22:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716687#M221535</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-03T22:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Converting variables to character when stacking datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716745#M221560</link>
      <description>&lt;P&gt;Define "different sources".&lt;/P&gt;
&lt;P&gt;If you get your data from separate (business) entities in different formats (e.g. xlsx vs. text), then you should streamline your orocess by setting up agreements with a unified format for data transfer files.&lt;/P&gt;
&lt;P&gt;If it's just multiple files in the same format, then the use of PROC IMPORT is the most likely culprit.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 06:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-variables-to-character-when-stacking-datasets/m-p/716745#M221560</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-04T06:47:26Z</dc:date>
    </item>
  </channel>
</rss>

