<?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: How to systematically unify variable attributes across multiple dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406156#M98849</link>
    <description>&lt;P&gt;If by this:&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;I've rearranged them so that all the column orders and names are the same across 30 dataset. &lt;/STRONG&gt; You mean that you have arranged some SAS datasets with the variables&amp;nbsp;in a common order I would be very tempted to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Proc Export all of the sets to&amp;nbsp;CSV files, may want to use the option Putnames=no so it is easier in the next step&lt;/P&gt;
&lt;P&gt;2) combine all the csv files into a single one&lt;/P&gt;
&lt;P&gt;3) Proc&amp;nbsp;import the large csv file with a large value for guessing rows.&lt;/P&gt;
&lt;P&gt;4) either modify the data step generated by proc import to use your desired variable names and formats or use proc datasets to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 21:15:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-10-20T21:15:50Z</dc:date>
    <item>
      <title>How to systematically unify variable attributes across multiple dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406152#M98848</link>
      <description>&lt;P&gt;I've come across this task that requires me to concatenate patient&amp;nbsp;information from 30 different sites/30 different tables, each table has 20 columns, I've rearranged them so that all the column orders and names are the same across 30 dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However,&amp;nbsp;each table was submitted by different sites, so there were lots of messy formats going on. i.e., patient_Ids are charter values in some sites' data (they were unique identifier, but can be anything, like UDWGER15581DE2) but are numeric values in others (1,2,3....). Same case for other variables, like drug_ID. For the same reason, this also means the length of the values, if there were character, were different, some Patient_ID are $15, some are $49.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To sum up, I was wondering if there is any easy way to systematically unify them? Instead of changing 20*30=600 variables by hand?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion will be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406152#M98848</guid>
      <dc:creator>LisaYIN9309</dc:creator>
      <dc:date>2017-10-20T20:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to systematically unify variable attributes across multiple dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406156#M98849</link>
      <description>&lt;P&gt;If by this:&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;I've rearranged them so that all the column orders and names are the same across 30 dataset. &lt;/STRONG&gt; You mean that you have arranged some SAS datasets with the variables&amp;nbsp;in a common order I would be very tempted to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Proc Export all of the sets to&amp;nbsp;CSV files, may want to use the option Putnames=no so it is easier in the next step&lt;/P&gt;
&lt;P&gt;2) combine all the csv files into a single one&lt;/P&gt;
&lt;P&gt;3) Proc&amp;nbsp;import the large csv file with a large value for guessing rows.&lt;/P&gt;
&lt;P&gt;4) either modify the data step generated by proc import to use your desired variable names and formats or use proc datasets to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 21:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406156#M98849</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-20T21:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to systematically unify variable attributes across multiple dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406188#M98865</link>
      <description>&lt;P&gt;You'd never do it by hand, I like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;solution the best, but if you want to keep it in SAS you should set up a master data set that has the formats you want and then use that to check variables one by one and convert. You'd design it for one data set and then automate but it's a pain. The writing it to a CSV file and then importing is a good idea.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 23:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406188#M98865</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T23:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to systematically unify variable attributes across multiple dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406290#M98899</link>
      <description>&lt;P&gt;If the problem is that some columns sometimes come up as numeric but you would like them to be character, you can convert the problematic columns with something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;length tmp1 $&lt;EM&gt;nn&lt;/EM&gt;;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;tmp1 = cats(myProblematicColumn);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;drop myProblematicColumn;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;rename tmp1=myProblematicColumn;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This doesn't affect the column if it is already character.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 19:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406290#M98899</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-10-21T19:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to systematically unify variable attributes across multiple dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406495#M98984</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/172549"&gt;@LisaYIN9309&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;If you can define an output format where all variables are character, this method may work: use the VVALUEX function.&lt;/P&gt;&lt;P&gt;Given a couple of tables with different variable types, but same variable names:&lt;/P&gt;&lt;PRE&gt;data a;
  length x 8 y $30 z $14;
  input x y z;
cards;
1 2 3
5 fdsfgh 2
3 c 31254
;run;

data b;
  length x $3 y 8 z $4;
  input x y z;
cards;
1rr 2 3
25 2 gg
33 31254 f
;run;&lt;/PRE&gt;&lt;P&gt;You&amp;nbsp;then define a model table where all variables are character, and long enough to hold all values, e.g.:&lt;/P&gt;&lt;PRE&gt;data want;
  length x $8 y $30 z $20;
  stop;
run;&lt;/PRE&gt;&lt;P&gt;You can then submit the same datastep&amp;nbsp;for each input to add your data to the model dataset - you may want to put that in a macro:&lt;/P&gt;&lt;PRE&gt;%macro add_table(table);&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp; if 0 then modify want;&lt;BR /&gt;&amp;nbsp; array out _character_;&lt;BR /&gt;&amp;nbsp; set &amp;amp;table(rename=(x=_1 y=_2 z=_3));&lt;BR /&gt;&amp;nbsp; do _N_=1 to dim(out);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out(_N_)=left(vvaluex(cats('_',_N_)));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;/PRE&gt;&lt;P&gt;Just make sure that the variables in the RENAME option do not collide with the real variable names.&lt;/P&gt;&lt;P&gt;Now you&amp;nbsp;need just one line of code for each input table:&lt;/P&gt;&lt;PRE&gt;%add_table(a);
%add_table(b);&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-systematically-unify-variable-attributes-across-multiple/m-p/406495#M98984</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-23T12:51:11Z</dc:date>
    </item>
  </channel>
</rss>

