<?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 Identify variables in the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857871#M338967</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have the following dataset and I want to create a new variable when sas finds any mention of the first word, it will output but am not getting the right outcome.&lt;/P&gt;&lt;P&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check1;&lt;BR /&gt;input gnn $ 1-50;&lt;BR /&gt;datalines;&lt;BR /&gt;ESOMEPRAZOLE&lt;BR /&gt;ESOMEPRAZOLE MAGNESIUM&lt;BR /&gt;ESOMEPRAZOLE/MAGNESIUM&lt;BR /&gt;ESOMEPRAZOLE_calcium&lt;BR /&gt;ESOMEPRAZOLE HCL&lt;/P&gt;&lt;P&gt;ESOMEPRAZOLE H ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check2;&lt;BR /&gt;set check1;&lt;BR /&gt;if GNN= "ESOMEPRAZOLE: " then new_drug = anagesic;&lt;BR /&gt;keep gnn;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I added a colon (:) to the drug name so that sas can find all mention but its not working.&lt;/P&gt;&lt;P&gt;This is what I want as output&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE MAGNESIUM&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE/MAGNESIUM&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE_calcium&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE HCL&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE H&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Wed, 08 Feb 2023 20:42:43 GMT</pubDate>
    <dc:creator>CathyVI</dc:creator>
    <dc:date>2023-02-08T20:42:43Z</dc:date>
    <item>
      <title>Identify variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857871#M338967</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have the following dataset and I want to create a new variable when sas finds any mention of the first word, it will output but am not getting the right outcome.&lt;/P&gt;&lt;P&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check1;&lt;BR /&gt;input gnn $ 1-50;&lt;BR /&gt;datalines;&lt;BR /&gt;ESOMEPRAZOLE&lt;BR /&gt;ESOMEPRAZOLE MAGNESIUM&lt;BR /&gt;ESOMEPRAZOLE/MAGNESIUM&lt;BR /&gt;ESOMEPRAZOLE_calcium&lt;BR /&gt;ESOMEPRAZOLE HCL&lt;/P&gt;&lt;P&gt;ESOMEPRAZOLE H ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data check2;&lt;BR /&gt;set check1;&lt;BR /&gt;if GNN= "ESOMEPRAZOLE: " then new_drug = anagesic;&lt;BR /&gt;keep gnn;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I added a colon (:) to the drug name so that sas can find all mention but its not working.&lt;/P&gt;&lt;P&gt;This is what I want as output&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE MAGNESIUM&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE/MAGNESIUM&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE_calcium&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE HCL&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ESOMEPRAZOLE H&lt;/TD&gt;&lt;TD&gt;Analgesics&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857871#M338967</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-02-08T20:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Identify variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857874#M338970</link>
      <description>&lt;P&gt;If your : addition was intended to match values that start with a specific word or string of characters then : would go on the equal sign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if GNN=: "ESOMEPRAZOLE" then new_drug = anagesic;&lt;/PRE&gt;
&lt;P&gt;If you include a space at the end of the string to match, as you did, then it would not match the value of&amp;nbsp;ESOMEPRAZOLE/MAGNESIUM or ESOMEPRAZOLE_calcium due to the / or _ .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if there is any chance that your variable GNN might sometimes have a value that starts with Esomeprazole, note the different case, then it doesn't match. You could work around that by using the UPCASE function to match the value regardless of original case:&lt;/P&gt;
&lt;PRE&gt;if upcase (GNN) =: "ESOMEPRAZOLE" then new_drug = anagesic;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857874#M338970</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-08T20:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Identify variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857876#M338971</link>
      <description>&lt;P&gt;Try the FIND function&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check1;
	input gnn $ 1-50;
	datalines;
ESOMEPRAZOLE
ESOMEPRAZOLE MAGNESIUM
NOT AN ANALGESIC
ESOMEPRAZOLE/MAGNESIUM
ESOMEPRAZOLE_calcium
ESOMEPRAZOLE HCL
ESOMEPRAZOLE H 
;

data check2;
	set check1;
	if find(GNN, "ESOMEPRAZOLE") then new_drug='Anagesic';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table undefined" aria-label="Data Set WORK.CHECK2"&gt;&lt;CAPTION aria-label="Data Set WORK.CHECK2"&gt;Result:&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;gnn&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;new_drug&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data"&gt;ESOMEPRAZOLE&lt;/TD&gt;
&lt;TD class="data"&gt;Anagesic&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="data"&gt;ESOMEPRAZOLE MAGNESIUM&lt;/TD&gt;
&lt;TD class="data"&gt;Anagesic&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="data"&gt;BAD DRUG&lt;/TD&gt;
&lt;TD class="data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="data"&gt;ESOMEPRAZOLE/MAGNESIUM&lt;/TD&gt;
&lt;TD class="data"&gt;Anagesic&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="data"&gt;ESOMEPRAZOLE_calcium&lt;/TD&gt;
&lt;TD class="data"&gt;Anagesic&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="data"&gt;ESOMEPRAZOLE HCL&lt;/TD&gt;
&lt;TD class="data"&gt;Anagesic&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="data"&gt;ESOMEPRAZOLE H&lt;/TD&gt;
&lt;TD class="data"&gt;Anagesic&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/857876#M338971</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2023-02-08T20:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Identify variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/858034#M339016</link>
      <description>&lt;P&gt;Thank you both. I wish I could accept both solutions because they both provided me a better understand of how to address the problem.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Thank you, you provide the solution and refined my initial thought process.&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;Thank you so much. I accepted your solution because when I looked into the entire data, I found some drug name with weird name. For example 0.9%&lt;SPAN&gt;ESOMEPRAZOLE or HCL&amp;nbsp;ESOMEPRAZOLE. I was able to use the find function to identify these ones.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 14:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-variables-in-the-dataset/m-p/858034#M339016</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2023-02-09T14:51:45Z</dc:date>
    </item>
  </channel>
</rss>

