<?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 do I create a new variable with the assigned number to different observations in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866728#M23618</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I have a categorical variable which contains multiple observations, for example, "A29.3" "C22.4" "E38.1" and "C43.6"... I want to create a new variable and assign them with the number. If I want&amp;nbsp;"A29.3" "C22.4" "E38.1" all to be 1 in the new column, what should I do?&lt;/P&gt;&lt;P&gt;I tried the code below, but when I use proc freq to check, I think SAS only transfers the last statement to 1 in the new column.&lt;/P&gt;&lt;P&gt;data CE;&lt;BR /&gt;set CE;&lt;BR /&gt;if final_cause="A29.3" then status=1;&lt;/P&gt;&lt;P&gt;if final_cause="C22.4" then status=1;&lt;/P&gt;&lt;P&gt;if final_cause="E38.1" then status=1;&lt;/P&gt;&lt;P&gt;else status=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Any idea on this? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 13:38:09 GMT</pubDate>
    <dc:creator>LarissaW</dc:creator>
    <dc:date>2023-03-28T13:38:09Z</dc:date>
    <item>
      <title>How do I create a new variable with the assigned number to different observations</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866728#M23618</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I have a categorical variable which contains multiple observations, for example, "A29.3" "C22.4" "E38.1" and "C43.6"... I want to create a new variable and assign them with the number. If I want&amp;nbsp;"A29.3" "C22.4" "E38.1" all to be 1 in the new column, what should I do?&lt;/P&gt;&lt;P&gt;I tried the code below, but when I use proc freq to check, I think SAS only transfers the last statement to 1 in the new column.&lt;/P&gt;&lt;P&gt;data CE;&lt;BR /&gt;set CE;&lt;BR /&gt;if final_cause="A29.3" then status=1;&lt;/P&gt;&lt;P&gt;if final_cause="C22.4" then status=1;&lt;/P&gt;&lt;P&gt;if final_cause="E38.1" then status=1;&lt;/P&gt;&lt;P&gt;else status=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Any idea on this? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 13:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866728#M23618</guid>
      <dc:creator>LarissaW</dc:creator>
      <dc:date>2023-03-28T13:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new variable with the assigned number to different observations</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866729#M23619</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427928"&gt;@LarissaW&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;I have a categorical variable which contains multiple observations, for example, "A29.3" "C22.4" "E38.1" and "C43.6"... I want to create a new variable and assign them with the number. If I want&amp;nbsp;"A29.3" "C22.4" "E38.1" all to be 1 in the new column, what should I do?&lt;/P&gt;
&lt;P&gt;I tried the code below, but when I use proc freq to check, I think SAS only transfers the last statement to 1 in the new column.&lt;/P&gt;
&lt;P&gt;data CE;&lt;BR /&gt;set CE;&lt;BR /&gt;if final_cause="A29.3" then status=1;&lt;/P&gt;
&lt;P&gt;if final_cause="C22.4" then status=1;&lt;/P&gt;
&lt;P&gt;if final_cause="E38.1" then status=1;&lt;/P&gt;
&lt;P&gt;else status=0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Any idea on this? Thanks!&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;I'm not sure I grasp the desired output. Saying something does not work does not really indicate what you do want. Please show us the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I note this is generally considered a sub-optimal practice to overwrite your data set CE with a new data set (although I guess there are times when its not so bad). Better would be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ce1;
    set ce;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 13:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866729#M23619</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-28T13:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a new variable with the assigned number to different observations</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866732#M23620</link>
      <description>&lt;P&gt;You ran three distinct IF/THEN/ELSE blocks.&amp;nbsp; So only the results of the last one will survive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either make it one long IF/THEN/ELSE IF.... ELSE series&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if final_cause="A29.3" then status=1;
else if final_cause="C22.4" then status=1;
else if final_cause="E38.1" then status=1;
else status=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of just use the IN operator so you only need one IF condition.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if final_cause in ("A29.3" "C22.4" "E38.1") then status=1;
else status=0;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Mar 2023 13:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/How-do-I-create-a-new-variable-with-the-assigned-number-to/m-p/866732#M23620</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-28T13:59:26Z</dc:date>
    </item>
  </channel>
</rss>

