<?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: Creating new variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566913#M75095</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry forgot to post the syntax;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if professionalcontact=. then visit=.;&lt;BR /&gt;else if professionalcontact in ('Admin', 'unkno') then delete;*this gives 11520 observations/visits;&lt;BR /&gt;else if professionalcontact in ('GP', 'AHP', 'HCA', 'Nurse') then visit=1;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The dot represents missing&amp;nbsp;&lt;EM&gt;numeric&lt;/EM&gt; values, but you work with&amp;nbsp;&lt;EM&gt;character&lt;/EM&gt; variables. Use an empty string ("") to represent missing character values.&lt;/P&gt;
&lt;P&gt;Since your first use of the new variable was numeric, it was defined as such, and all attempts to assign character values to it will result in missing values, and NOTEs with ERRORs and finally a WARNING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before you expand this if/then/else chain, take a look at the data step select statement (not the SQL one).&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jun 2019 15:00:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-06-18T15:00:27Z</dc:date>
    <item>
      <title>Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566863#M75088</link>
      <description>&lt;P&gt;I want to create a new variable from an existing variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The existing variable has following values- GP, AHP, HCA, Nurse, admin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new variable which does not include 'admin' and missing values, and coded '1' for all other values (GP, AHP, HCA, Nurse).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written the following syntax but it's giving '.' for all values in the new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566863#M75088</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T13:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566866#M75089</link>
      <description>&lt;P&gt;Sorry forgot to post the syntax;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if professionalcontact=. then visit=.;&lt;BR /&gt;else if professionalcontact in ('Admin', 'unkno') then delete;*this gives 11520 observations/visits;&lt;BR /&gt;else if professionalcontact in ('GP', 'AHP', 'HCA', 'Nurse') then visit=1;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566866#M75089</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T13:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566868#M75090</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The first thing I would do is run a PROC FREQ on the input data set to find out what values _EXACTLY_ are in the field or variable PROFESSIONALCONTACT -- to check case, length, etc. Then you would be able to tell whether the number deleted by your IF statement was correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566868#M75090</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-06-18T13:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566870#M75091</link>
      <description>&lt;P&gt;If possible, can you provide the logic to create a dummy data set that aligns with the dataset you are working to manipulate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use the instructions on this page to help, &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_self"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&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;That would give a better starting point for us to understand what the starting data looks like and how the logic you are using afterwards is interacting with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566870#M75091</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-18T13:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566871#M75092</link>
      <description>&lt;P&gt;Hi Thanks, here is the freq proc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV class="c proctitle"&gt;The FREQ Procedure&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;ProfessionalContact Frequency Percent CumulativeFrequency CumulativePercentAHPAdminGPHCANurseUnknoFrequency Missing = 1 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;660&lt;/TD&gt;&lt;TD&gt;3.58&lt;/TD&gt;&lt;TD&gt;660&lt;/TD&gt;&lt;TD&gt;3.58&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6923&lt;/TD&gt;&lt;TD&gt;37.54&lt;/TD&gt;&lt;TD&gt;7583&lt;/TD&gt;&lt;TD&gt;41.12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8147&lt;/TD&gt;&lt;TD&gt;44.18&lt;/TD&gt;&lt;TD&gt;15730&lt;/TD&gt;&lt;TD&gt;85.29&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;68&lt;/TD&gt;&lt;TD&gt;0.37&lt;/TD&gt;&lt;TD&gt;15798&lt;/TD&gt;&lt;TD&gt;85.66&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1925&lt;/TD&gt;&lt;TD&gt;10.44&lt;/TD&gt;&lt;TD&gt;17723&lt;/TD&gt;&lt;TD&gt;96.10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;719&lt;/TD&gt;&lt;TD&gt;3.90&lt;/TD&gt;&lt;TD&gt;18442&lt;/TD&gt;&lt;TD&gt;100.00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566871#M75092</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T13:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566872#M75093</link>
      <description>&lt;P&gt;Sorry it changed the format a little bit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each value in the left column represent number for each of the following categories;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;AHP &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Admin &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;GP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;HCA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Nurse&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Unkno&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566872#M75093</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T13:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566907#M75094</link>
      <description>&lt;P&gt;And here is snapshot of the the new variable 'visit' created from existing variable 'professionalcontact'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp; &amp;nb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LE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 14:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566907#M75094</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T14:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566913#M75095</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry forgot to post the syntax;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if professionalcontact=. then visit=.;&lt;BR /&gt;else if professionalcontact in ('Admin', 'unkno') then delete;*this gives 11520 observations/visits;&lt;BR /&gt;else if professionalcontact in ('GP', 'AHP', 'HCA', 'Nurse') then visit=1;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The dot represents missing&amp;nbsp;&lt;EM&gt;numeric&lt;/EM&gt; values, but you work with&amp;nbsp;&lt;EM&gt;character&lt;/EM&gt; variables. Use an empty string ("") to represent missing character values.&lt;/P&gt;
&lt;P&gt;Since your first use of the new variable was numeric, it was defined as such, and all attempts to assign character values to it will result in missing values, and NOTEs with ERRORs and finally a WARNING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before you expand this if/then/else chain, take a look at the data step select statement (not the SQL one).&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566913#M75095</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-18T15:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566919#M75096</link>
      <description>&lt;P&gt;Thanks for helping but I couldn't get '&lt;SPAN&gt;Before you expand this if/then/else chain, take a look at the data step select statement (not the SQL one).'. Can you elaborate further please?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BW&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;S&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566919#M75096</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T15:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566921#M75097</link>
      <description>&lt;P&gt;Look at this example for your logic:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (professionalcontact);
  when ('') visit = .;
  when ('Admin', 'unkno') delete;
  when ('GP', 'AHP', 'HCA', 'Nurse') visit = 1;
  otherwise; /* if you omit this, you will be alerted to an unexpected value by an ERROR */
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I just noted that you actually&amp;nbsp;&lt;EM&gt;want&lt;/EM&gt; to have a numeric value in visit, so ignore that part of my previous post.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566921#M75097</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-18T15:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566922#M75098</link>
      <description>&lt;P&gt;Very helpful indeed! thanks for all your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-variable/m-p/566922#M75098</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-06-18T15:15:37Z</dc:date>
    </item>
  </channel>
</rss>

