<?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: Converting character variable to numeric in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905851#M40468</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/453974"&gt;@SIMMII&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey Patrick, may I ask what you mean by HAVE data? In the parts you highlighted, do I have to create a new dataset or keep the ps2_train file? I'm still very new to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First thing to do is get out of the habit of writing code like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XYZ;
  set XYZ;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The name on the DATA statement is the dataset you are trying to CREATE.&amp;nbsp; The name on the SET statement is the dataset you are reading into the data step.&amp;nbsp; So you are replacing your existing dataset with new dataset.&amp;nbsp; If there is some mistake in the logic of the data step you have destroyed your original XYZ dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead always make a NEW dataset.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  set have;
  ....
run;

data step2;
  set step1;
....
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can clean up later if you want using PROC DELETE.&amp;nbsp; Or just let SAS remove all of the WORK datasets when you close your SAS session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure to share TEXT (such as SAS Code, SAS Logs, or DATA).&amp;nbsp; I you post code and data as PICTURES instead of actual text then people trying to help cannot just copy the code and make fixes to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And make sure to use the insert Code or Insert SAS Code button on the forum editor to get a pop-up window to paste/type/edit the text or SAS code you want to share.&amp;nbsp; That way the forum software does not try to flow the text into paragraphs.&amp;nbsp; It also makes it stand out as different from the text of the actual question/posting.&lt;/P&gt;</description>
    <pubDate>Sat, 02 Dec 2023 17:21:56 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-02T17:21:56Z</dc:date>
    <item>
      <title>Converting character variable to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905799#M40459</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried running this code for a file named ps2_train which initially looks like this (table of dummy variables renamed):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ps2_question2.sc3.PNG" style="width: 790px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90702i728D8B94D9A4D20B/image-size/large?v=v2&amp;amp;px=999" role="button" title="ps2_question2.sc3.PNG" alt="ps2_question2.sc3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And it gave me this output data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ps2_question2.sc4.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90703i3D3DD03C4499B416/image-size/large?v=v2&amp;amp;px=999" role="button" title="ps2_question2.sc4.PNG" alt="ps2_question2.sc4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But then I tried this code to convert the y variable (character variable) into a numeric:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ps2_question2.PNG" style="width: 403px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90700i9585A384AC89390E/image-size/large?v=v2&amp;amp;px=999" role="button" title="ps2_question2.PNG" alt="ps2_question2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But it gave me this output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ps2_question2_sc2.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90701i8626DEB11C6328A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="ps2_question2_sc2.PNG" alt="ps2_question2_sc2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My question is: how can I convert the y variable into a numeric one and have it incorporated into the original output that I showed (with all the variables x1, job, married, education,etc.)??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 04:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905799#M40459</guid>
      <dc:creator>SIMMII</dc:creator>
      <dc:date>2023-12-02T04:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905809#M40460</link>
      <description>&lt;P&gt;Post the log from your code by copy/pasting the log&amp;nbsp;&lt;U&gt;text&lt;/U&gt; into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In the future, post your code&amp;nbsp;&lt;U&gt;text&lt;/U&gt; in a window opened with the "little running man" button right next to the one indicated.&amp;nbsp;&lt;STRONG&gt;Do not post pictures&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 06:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905809#M40460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-12-02T06:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905824#M40462</link>
      <description>&lt;P&gt;Below screenshot is from the answer I gave you on your &lt;A href="https://communities.sas.com/t5/New-SAS-User/Converting-character-variables-to-numeric/m-p/905510" target="_self"&gt;previous question&lt;/A&gt; for the same challenge.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1701511629949.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90709iAB16E6851290A41A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1701511629949.png" alt="Patrick_0-1701511629949.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The first data step in this sample code is to create some HAVE data in order to provide some self-contained code that can run on its own. This because you haven't provided such sample HAVE data.&lt;/P&gt;
&lt;P&gt;You need of course to use your real table work.ps2_train however it's called in reality. So do not execute the first data step and use in the set statement of the 2nd data step the name of your actual table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 10:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905824#M40462</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-02T10:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905850#M40467</link>
      <description>&lt;P&gt;Hey Patrick, may I ask what you mean by HAVE data? In the parts you highlighted, do I have to create a new dataset or keep the ps2_train file? I'm still very new to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 17:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905850#M40467</guid>
      <dc:creator>SIMMII</dc:creator>
      <dc:date>2023-12-02T17:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905851#M40468</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/453974"&gt;@SIMMII&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey Patrick, may I ask what you mean by HAVE data? In the parts you highlighted, do I have to create a new dataset or keep the ps2_train file? I'm still very new to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First thing to do is get out of the habit of writing code like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data XYZ;
  set XYZ;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The name on the DATA statement is the dataset you are trying to CREATE.&amp;nbsp; The name on the SET statement is the dataset you are reading into the data step.&amp;nbsp; So you are replacing your existing dataset with new dataset.&amp;nbsp; If there is some mistake in the logic of the data step you have destroyed your original XYZ dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead always make a NEW dataset.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  set have;
  ....
run;

data step2;
  set step1;
....
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can clean up later if you want using PROC DELETE.&amp;nbsp; Or just let SAS remove all of the WORK datasets when you close your SAS session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure to share TEXT (such as SAS Code, SAS Logs, or DATA).&amp;nbsp; I you post code and data as PICTURES instead of actual text then people trying to help cannot just copy the code and make fixes to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And make sure to use the insert Code or Insert SAS Code button on the forum editor to get a pop-up window to paste/type/edit the text or SAS code you want to share.&amp;nbsp; That way the forum software does not try to flow the text into paragraphs.&amp;nbsp; It also makes it stand out as different from the text of the actual question/posting.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2023 17:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905851#M40468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-02T17:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character variable to numeric</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905856#M40469</link>
      <description>I see, thank you very much! I'll use the insert code feature next time, sorry about that!</description>
      <pubDate>Sat, 02 Dec 2023 17:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-variable-to-numeric/m-p/905856#M40469</guid>
      <dc:creator>SIMMII</dc:creator>
      <dc:date>2023-12-02T17:52:34Z</dc:date>
    </item>
  </channel>
</rss>

