<?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: If ID equals A, keep the value from variable A in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644434#M21974</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;This works great - thank you very much!&lt;/P&gt;</description>
    <pubDate>Fri, 01 May 2020 02:01:03 GMT</pubDate>
    <dc:creator>bkq32</dc:creator>
    <dc:date>2020-05-01T02:01:03Z</dc:date>
    <item>
      <title>If ID equals A, keep the value from variable A</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644421#M21971</link>
      <description>&lt;P&gt;This is the dataset I have and the one I want to create. I'd like to create a new variable ORIGVALUE that takes the value of the PATIENT_ID_: variables where the variable name suffix equals the PATIENT_ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 length patient_id 8. variable $200.;
 input patient_id variable $ patient_id_25 patient_id_2020 patient_id_2029;
cards;
25 MomWtGain 21 25 8
25 Weight 4054 2835 2920
2020 CigsPerDay 0 20 0
2029 MomWtGain 21 25 8
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length patient_id 8. variable $200.;
input patient_id variable $ origvalue $;
cards;
25 MomWtGain 21
25 Weight 4054
2020 CigsPerDay 20
2029 MomWtGain 8
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can do it manually via the following, but have too many records and PATIENT_ID_: columns to do this. Is there a way to automate this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data havea ( keep = patient_id variable patient_id_25 
               rename = ( patient_id_25 = origvalue ) )
     haveb ( keep = patient_id variable patient_id_2020 
               rename = ( patient_id_2020 = origvalue ) )
     havec ( keep = patient_id variable patient_id_2029 
               rename = ( patient_id_2029 = origvalue ) );
 set have;
 if patient_id = 25 then output havea;
 if patient_id = 2020 then output haveb;
 if patient_id = 2029 then output havec;
run;


data want;
 set havea haveb havec;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 00:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644421#M21971</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2020-05-01T00:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: If ID equals A, keep the value from variable A</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644427#M21972</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288620"&gt;@bkq32&lt;/a&gt;&amp;nbsp; Please see if this helps&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 length patient_id 8. variable $200.;
 input patient_id variable $ patient_id_25 patient_id_2020 patient_id_2029;
cards;
25 MomWtGain 21 25 8
25 Weight 4054 2835 2920
2020 CigsPerDay 0 20 0
2029 MomWtGain 21 25 8
;
run;

data want;
 set have;
 array p patient_id_25--patient_id_2029;
 do over p;
  if input(scan(vname(p),-1,'_'),best.)= patient_id then do;
   origvalue=p;
   leave;
  end;
 end;
 drop patient_id_25--patient_id_2029;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 01:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644427#M21972</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-01T01:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: If ID equals A, keep the value from variable A</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644434#M21974</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;This works great - thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 02:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-ID-equals-A-keep-the-value-from-variable-A/m-p/644434#M21974</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2020-05-01T02:01:03Z</dc:date>
    </item>
  </channel>
</rss>

