<?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: Adding one variable to dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372688#M89153</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/123179"&gt;@india2016&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;one member has multiple ID's so when ID repeats then that should come in ID2.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;WHICH of the repeats should end up in id2? The first, the last, one based on some kind of precedence?&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jul 2017 10:16:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-07-03T10:16:38Z</dc:date>
    <item>
      <title>Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372679#M89146</link>
      <description>&lt;P&gt;I have dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;member &amp;nbsp;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;12Jun2017&lt;/P&gt;&lt;P&gt;102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp;14May2017&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp;19July2017&lt;/P&gt;&lt;P&gt;103 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp;24Jun2017&lt;/P&gt;&lt;P&gt;102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; 13May2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want output as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;member &amp;nbsp;id &amp;nbsp; id2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp;&lt;/P&gt;&lt;P&gt;101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 12Jun2017&lt;/P&gt;&lt;P&gt;102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14May2017&lt;/P&gt;&lt;P&gt;103 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24Jun2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please suggest any solution.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 09:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372679#M89146</guid>
      <dc:creator>india2016</dc:creator>
      <dc:date>2017-07-03T09:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372681#M89148</link>
      <description>&lt;P&gt;What if a member has more than two entries? Which id should be set as id2?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 09:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372681#M89148</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-03T09:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372683#M89149</link>
      <description>&lt;P&gt;What to do with date here? &amp;nbsp;Your main part is a simple transpose, however you have different dates for the visits. &amp;nbsp;Is it just one visit or possibly more? &amp;nbsp;If you only want one date, then sort the data, transpose up by member, then merge date of first back on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 09:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372683#M89149</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-03T09:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372685#M89151</link>
      <description>&lt;P&gt;one member has multiple ID's so when ID repeats then that should come in ID2.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 09:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372685#M89151</guid>
      <dc:creator>india2016</dc:creator>
      <dc:date>2017-07-03T09:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372688#M89153</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/123179"&gt;@india2016&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;one member has multiple ID's so when ID repeats then that should come in ID2.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;WHICH of the repeats should end up in id2? The first, the last, one based on some kind of precedence?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 10:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372688#M89153</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-03T10:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372689#M89154</link>
      <description>Actually I want unique member and his multiple ID's should comes in front of 'Member'..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;INFORMATION ABOUT "Date"&lt;BR /&gt;&lt;BR /&gt;which date occurs first that should comes against' Member'..</description>
      <pubDate>Mon, 03 Jul 2017 10:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372689#M89154</guid>
      <dc:creator>india2016</dc:creator>
      <dc:date>2017-07-03T10:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372692#M89156</link>
      <description>&lt;P&gt;You're still writing Klingon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this come near:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input member id $ date:date9.;
format date date9.;
cards;
101 1 12Jun2017
102 3 14May2017
101 2 19Jul2017
103 5 24Jun2017
102 4 13May2017
run;

proc sort data=have;
by member id;
run;

data want;
set have (rename=(id=old_id date=old_date));
by member;
retain id id2 date;
format date date9.;
if first.member
then do;
  date = old_date;
  id = old_id;
  id2 = ' ';
end;
else id2 = old_id;
if last.member then output;
drop old_id old_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jul 2017 10:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372692#M89156</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-07-03T10:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372728#M89163</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input member id $ date:date9.;
format date date9.;
cards;
101 1 12Jun2017
102 3 14May2017
101 2 19Jul2017
103 5 24Jun2017
102 4 13May2017
;
run;
proc sort data=have;
 by member id;
run;
data temp;
 set have;
 by member;
 retain d;
 if first.member then d=date;
 drop date;
 format d date9.;
run;
proc transpose data=temp out=want prefix=id;
 by member d;
 var id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jul 2017 13:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372728#M89163</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-03T13:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372757#M89171</link>
      <description>&lt;P&gt;Hi, another idea (could rename DATE_1 and ID variables with PROC DATASETS or as a data set option for data set Y in PROC SUMMARY) ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data x;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;input member id :$1. date :date9.;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;format date date9.;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;101 1 12Jun2017&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;102 3 14May2017&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;101 2 19Jul2017&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;103 5 24Jun2017&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;102 4 13May2017&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;proc summary data=x nway;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;class member;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;output out=y (keep=member id: date_1) idgroup(out[2] (date id)=);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;DATA SET: y&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;member &amp;nbsp;date_1 &amp;nbsp; id_1 id_2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;101 &amp;nbsp; 12JUN2017 &amp;nbsp;1 &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;102 &amp;nbsp; 14MAY2017 &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;103 &amp;nbsp; 24JUN2017 &amp;nbsp;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 15:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372757#M89171</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2017-07-03T15:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372792#M89174</link>
      <description>&lt;P&gt;Piggybacking off of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13759"&gt;@MikeZdeb&lt;/a&gt;&amp;nbsp;has, here are a couple of other options/things to consider.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In case your data is not sorted, I would recommend sorting the data so that the date displayed is the earliest date (Assuming that is what you are looking for).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also you can create a macro variable in case your dataset has more than two records per member. &amp;nbsp;The macro variable will resolve to the maximum number of records for a member (In the instance below it would be 3, since there are 3 records for member "101". &amp;nbsp;For your initial dataset, it would be 2 since both members "101" and "102" have 2 records). &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have added an additional line of data to your data for illustration purposes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data old;
input member id date :date9.;
format date date9.;
datalines;
101 6 23Oct2017    /* Additional line of data */
101 1 12Jun2017
102 3 14May2017
101 2 19Jul2017
103 5 24Jun2017
102 4 13May2017
;
run;

Proc Sort data = old;
By member id date;
run;

/* Creates your macro variable (n) */
Proc Sql noprint;
select max(n) into :n
from (select count(*) as n from old group by member);
quit;

/* Creates the output */
proc summary data=old nway;
class member;
output out=new (keep=member id: date_1) idgroup(out[&amp;amp;n] (id date)=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jul 2017 17:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372792#M89174</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2017-07-03T17:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Adding one variable to dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372809#M89177</link>
      <description>&lt;P&gt;And you can do some reading for more explanation&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Transposing Data Using PROC SUMMARY'S IDGROUP Option (John King, Mike Zdeb)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings10/102-2010.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings10/102-2010.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 18:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-one-variable-to-dataset/m-p/372809#M89177</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2017-07-03T18:26:44Z</dc:date>
    </item>
  </channel>
</rss>

