<?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: merging datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225508#M40489</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS9.4 Windows64. The SAS files uploaded were in imported from (stata) dta files.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Sep 2015 04:21:43 GMT</pubDate>
    <dc:creator>mspak</dc:creator>
    <dc:date>2015-09-15T04:21:43Z</dc:date>
    <item>
      <title>merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225311#M40427</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to merge two datasets with different informat of a variable. I tried to change the variable "STATE" from a numeric variable to a character variable using PUT function&amp;nbsp;prior&amp;nbsp;to merging but I failed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone recommend a better way to solve the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2015 15:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225311#M40427</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-13T15:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225312#M40428</link>
      <description>&lt;P&gt;Unable to understand your question. Better to show the program and the Log.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2015 15:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225312#M40428</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2015-09-13T15:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225321#M40429</link>
      <description>&lt;P&gt;The INFORMAT attached to a variable has no impact on whether you can merge by it.&lt;/P&gt;&lt;P&gt;If the variables are different TYPE then you will not be able combine the datasets at all, let alone merge by that variable.&lt;/P&gt;&lt;P&gt;You cannot change the type of variable. You can make a new variable and rename it.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar=put(state,z2.);
rename newvar=state state=oldstate;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You could also merge directly using SQL.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from a,b 
where a.state = put(b.state,Z2.)
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Sep 2015 18:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225321#M40429</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-13T18:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225337#M40430</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These two files attached. I try to merge these two files together but the format of the variable "STATE" are different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TQ.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 03:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225337#M40430</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-14T03:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225352#M40438</link>
      <description>&lt;P&gt;With which SAS version and on which platform did you create those datasets? I can't open them with 9.2 on Win64.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 10:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225352#M40438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-09-14T10:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225374#M40449</link>
      <description>&lt;P&gt;This is how I would solve the problem assuming that you want to get all of the inherent and fyear records from both set1 and set2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* get dataset of distinct states and counties */
proc sql;
 create table state_county as
 select distinct a.fips, a.county as county_num, b.state, b.name as county_name
 from set2 as a join
	set1 as b on a.fips = b.fips;
run;

/* concatenate the tables together to get inherent and fyear data from each set */
/* keep state and county information                                            */
proc sql;
 create table combined as
 select a.*, b.inherent, b.fyear
 from state_county as a join
 	set2 as b on a.fips = b.fips
union
select a.*, b.inherent, b.fyear
 from state_county as a join
 	set1 as b on a.fips = b.fips
	;
quit;

/* sort for fips and year */
proc sort data=combined;
 by fips fyear;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Sep 2015 14:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225374#M40449</guid>
      <dc:creator>ToddB</dc:creator>
      <dc:date>2015-09-14T14:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225389#M40451</link>
      <description>&lt;P&gt;Hi. &amp;nbsp;I think that you want to CONCATENATE (not MERGE) the two data sets you posted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;STATE is a state name in data set SET1 and a state code in data set SET2. &amp;nbsp;&lt;/P&gt;&lt;P&gt;So ... make two new variables for the new data set, STATE_CODE and STATE_NAME.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NAME has a name and state in data set SET1 but only a name in data set SET2.&lt;/P&gt;&lt;P&gt;So ... get rid of the state portion&amp;nbsp;of NAME&amp;nbsp;(each observation will have a STATE_CODE and STATE_NAME)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data set SET1 has no county numbers&lt;/P&gt;&lt;P&gt;So ... use the FIPS code to add a county number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Assuming that I'm correct, try this ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* first ... remove the formats and informats from both data sets (useless);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc datasets lib=z;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;modify set1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;format _all_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;informat _all_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;modify set2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;format _all_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;informat _all_;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* second ... combine (CONCATENATE) the two data sets with SET statements;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data one_two;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;length name $36;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;format state_code z2. county z3. fips z5.;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set z.set1 (in=one rename=(state=state_name)) z.set2 (rename=(state=state_code));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if one then do; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;state_code = input(substr(put(fips,z5.),1,2),2.);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;county = input(substr(put(fips,z5.),3,3),3.);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;else do;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;state_name = fipname(state_code);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp;name = scan(name,1,',');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The combined data set ONE_TWO has 15,714 observations. &amp;nbsp;PROC CONTENTS shows ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;# Variable &amp;nbsp; Type Len Format Label&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;7 FYEAR &amp;nbsp; &amp;nbsp; &amp;nbsp;Num &amp;nbsp; 8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;6 INHERENT &amp;nbsp; Num &amp;nbsp; 8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;3 county &amp;nbsp; &amp;nbsp; Num &amp;nbsp; 8 &amp;nbsp; Z3. &amp;nbsp;3-digit county fips number&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;4 fips &amp;nbsp; &amp;nbsp; &amp;nbsp; Num &amp;nbsp; 8&amp;nbsp; &amp;nbsp;Z5.&amp;nbsp;&amp;nbsp;FIPS Code&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;1 name &amp;nbsp; &amp;nbsp; &amp;nbsp; Char 36 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;County Name&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;2 state_code Num &amp;nbsp; 8 &amp;nbsp; Z2. &amp;nbsp;State Census Code&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;5 state_name Char 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;State Name&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 16:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225389#M40451</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-09-14T16:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225390#M40452</link>
      <description>&lt;P&gt;SET1:&lt;/P&gt;&lt;P&gt;STATE - Type=TEXT, $20&lt;/P&gt;&lt;P&gt;SET2:&lt;/P&gt;&lt;P&gt;STATE - Type=NUMERIC, Format=STATE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In one data set you have a character variable for state and in the second you have a numeric variable that is mapped using a format.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;&amp;nbsp;you can use the option noftmerr to view the datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6107"&gt;@mspak﻿&lt;/a&gt;&amp;nbsp;something like the following should work - rename old variable state to state_code and create a new variable state that is character. Then merge the datasets. This won't work exactly as I suspect you have more than STATE in your merge condition but it's a starting point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SET2_NEW;
set SET2(rename=state=state_code);
state=put(state_code, state.);
run;

*Appropriate sorts...;

data want;
merge set1 set2;
by state;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 16:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225390#M40452</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-14T16:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225508#M40489</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS9.4 Windows64. The SAS files uploaded were in imported from (stata) dta files.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 04:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225508#M40489</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-15T04:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225509#M40490</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for all the solutions and suggestions provided. I truly appreciate your contributions. I finally manage to combine 2 datasets.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 04:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/225509#M40490</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2015-09-15T04:27:37Z</dc:date>
    </item>
  </channel>
</rss>

