<?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 How to separate data that have some distinct fields, but other fields that are unique? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721611#M27798</link>
    <description>&lt;P&gt;I have a data set in that is in this format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Email_type&amp;nbsp; &amp;nbsp; Email&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Business&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xyz@blank&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Personal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc@blank&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Business&amp;nbsp; &amp;nbsp; &amp;nbsp; 123@blank&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Personal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 456@blank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to get it in this format,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp;Personal_Email Business_email&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc@blank&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;A href="mailto:xyz@blank" target="_blank" rel="noopener"&gt;xyz@blank&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking of sub setting the first data set with a where email_type = "Business" and then merging the two data sets using Name as a key. But I am wondering if there is a more effective way of dealing with this type of situation, as it shows up frequently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Feb 2021 16:28:49 GMT</pubDate>
    <dc:creator>helloagainoh2</dc:creator>
    <dc:date>2021-02-24T16:28:49Z</dc:date>
    <item>
      <title>How to separate data that have some distinct fields, but other fields that are unique?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721611#M27798</link>
      <description>&lt;P&gt;I have a data set in that is in this format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Email_type&amp;nbsp; &amp;nbsp; Email&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Business&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xyz@blank&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Personal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc@blank&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Business&amp;nbsp; &amp;nbsp; &amp;nbsp; 123@blank&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Personal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 456@blank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to get it in this format,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp;Personal_Email Business_email&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc@blank&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;A href="mailto:xyz@blank" target="_blank" rel="noopener"&gt;xyz@blank&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking of sub setting the first data set with a where email_type = "Business" and then merging the two data sets using Name as a key. But I am wondering if there is a more effective way of dealing with this type of situation, as it shows up frequently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 16:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721611#M27798</guid>
      <dc:creator>helloagainoh2</dc:creator>
      <dc:date>2021-02-24T16:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate data that have some distinct fields, but other fields that are unique?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721614#M27800</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364863"&gt;@helloagainoh2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data set in that is in this format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Email_type&amp;nbsp; &amp;nbsp; Email&lt;/P&gt;
&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Business&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;xyz@blank&lt;/P&gt;
&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Personal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc@blank&lt;/P&gt;
&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Business&amp;nbsp; &amp;nbsp; &amp;nbsp; 123@blank&lt;/P&gt;
&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Personal&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 456@blank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is to get it in this format,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp;Personal_Email Business_email&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc@blank&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;A href="mailto:xyz@blank" target="_blank" rel="noopener"&gt;xyz@blank&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking of sub setting the first data set with a where email_type = "Business" and then merging the two data sets using Name as a key. But I am wondering if there is a more effective way of dealing with this type of situation, as it shows up frequently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you only have one value for each of the email_types per id (only one personal and/or only one business) then this may help:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sort data=have;
   by id;
run;

Proc transpose data=have
        out=want prefix=email;
   by id;
   id email_type;
   var email;
run;
&lt;/PRE&gt;
&lt;P&gt;This will create a new variable with the name of "email" as prefix and the value of email_type as the rest of the name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are other variables that need to be considered that is another story as we would need a more complete example of the data and the desired result.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 16:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721614#M27800</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-24T16:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate data that have some distinct fields, but other fields that are unique?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721616#M27801</link>
      <description>&lt;P&gt;If things get more complicated, you could do a controlled transposition with a DATA step, like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines truncover;
   input Name:$1. Email_type:$8.   Email:$20.;
datalines;
A Business xyz@blank
A Personal abc@blank
B Business 123@blank
B Personal 456@blank
;

data want;
   set have;
   by name;
   length Personal_Email Business_Email $20;
   retain Personal_Email Business_Email ;
   if first.name then do;
      call missing(Personal_Email, Business_Email);
   end; 
   if email_type="Business" then Business_Email=Email;
   else if email_type="Personal" then Personal_Email=Email;
   if last.name then output;
   drop Email:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 16:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-separate-data-that-have-some-distinct-fields-but-other/m-p/721616#M27801</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-02-24T16:44:28Z</dc:date>
    </item>
  </channel>
</rss>

