<?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 do I change values of a variable by values from a different dataset (trade name to generic) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631448#M187098</link>
    <description>&lt;P&gt;Thanks Keintz. This works too!&lt;/P&gt;</description>
    <pubDate>Thu, 12 Mar 2020 04:42:31 GMT</pubDate>
    <dc:creator>Talat</dc:creator>
    <dc:date>2020-03-12T04:42:31Z</dc:date>
    <item>
      <title>How do I change values of a variable by values from a different dataset (trade name to generic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631428#M187090</link>
      <description>&lt;P&gt;I have a data set where patients have stated the medicine they took. I need to convert the medicine names to the generic name. Doing it by 'if..then' statement' would be too time-consuming.&amp;nbsp; There should be a simple Macro approach but got stuck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached two datasets:&lt;/P&gt;&lt;P&gt;Tes datat~ has 8 variables: ID=cid.&amp;nbsp; med1-med7 (name of medicines as provided)&lt;/P&gt;&lt;P&gt;Allmeds~ 3 variables. 'Gname' is an index for all the med1-med7 names provided by the patients.&amp;nbsp; 'Generic' is the generic name of the corresponding drug in 'Gname'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to replace the med1-med7 in the Test dataset with the corresponding generic name from Allmeds data set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;the 28th subject stated the use of Paracetamol&amp;nbsp; &amp;nbsp;Ambrox.&lt;/P&gt;&lt;P&gt;In the new dataset, it should be:&amp;nbsp; Acetominophen&amp;nbsp; Ambroxol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;-Talat&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no problem if these are new variables (gmed1-gmed7).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 01:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631428#M187090</guid>
      <dc:creator>Talat</dc:creator>
      <dc:date>2020-03-12T01:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change values of a variable by values from a different dataset (trade name to generic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631430#M187092</link>
      <description>&lt;P&gt;You could use your allmed table to create a format. Then either just apply the format to the variables in test or create new variables using syntax like: genMed1=put(med1, &amp;lt;format name&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here the code for creating a format from a dataset like documented &lt;A href="https://go.documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n1e19y6lrektafn1kj6nbvhus59w.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fmt_source;
  set allmed(keep= gname generic rename=(gname=start generic=label));
  retain fmtname '$medNameGen' type 'c';
run;

proc format cntlin=fmt_source;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 04:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631430#M187092</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-12T04:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change values of a variable by values from a different dataset (trade name to generic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631439#M187095</link>
      <description>&lt;P&gt;This program creates 7 new variables gmed1-gmed7 to correspond to your old variables.&amp;nbsp; If the old medicine is not blank, and is found in the allmed table, then the corresponding new variable will have the generic name.&amp;nbsp; But if the old variables is not matched in the allmed table the generic variable will have a blank value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=i gname generic);
  set test;
  if _n_=1 then do;
    if 0 then set allmed (keep=gname generic);
    declare hash h (dataset:'allmed (keep=gname generic)');
      h.definekey('gname');
      h.definedata('generic');
      h.definedone();
  end;
  array meds  {*}     med1-med7;
  array gmeds {*} $20 gmed1-gmed7;
  do i=1 to 7;
    if meds{i}=' ' then continue;
    if h.find(key:meds{i})=0 then gmeds{i}=generic;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This simple lookup action is probably the most common usage of hash objects.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 03:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631439#M187095</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-03-12T03:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change values of a variable by values from a different dataset (trade name to generic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631441#M187096</link>
      <description>&lt;P&gt;Thanks Patrick. It worked perfectly! Such simple codes!!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 04:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631441#M187096</guid>
      <dc:creator>Talat</dc:creator>
      <dc:date>2020-03-12T04:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change values of a variable by values from a different dataset (trade name to generic)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631448#M187098</link>
      <description>&lt;P&gt;Thanks Keintz. This works too!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 04:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-values-of-a-variable-by-values-from-a-different/m-p/631448#M187098</guid>
      <dc:creator>Talat</dc:creator>
      <dc:date>2020-03-12T04:42:31Z</dc:date>
    </item>
  </channel>
</rss>

