<?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 can I use SAS to combine my variables to create a completely new variable? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620225#M19510</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299741"&gt;@SM8&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have two variables in my dataset, pounds and Ounces. I am trying to combine these variables into a total weight variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if an observation has a recorded 8 pounds and a recorded 2 ounces, I want to create this new variable to say 8.2. Is this possible in SAS, and if so, how do I accomplish this?&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;Be very careful of that sort of non-standard representation. If you want a decimal version you would be better off where 2 ounces is represented as 0.125 then you actually have unit for the variable in pounds:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newweight = pounds + ounces/16;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would be the way with a data step to convert ounces to pounds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would have to very clearly describe the actual advantage or use of storing the value as 8.2. You couldn't do substraction, such as determining change in weight, or look up with standard tables a value as you propose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps change the whole value to ounces? Newweight = pounds*16 + ounces;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dealt with some data that was provided in a form similar to what you propose only the "decimal" portion was fourths of a pound. And none of the uses wanted that sort of units so had to be converted to actual pounds before anything could be done.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jan 2020 16:46:14 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-01-27T16:46:14Z</dc:date>
    <item>
      <title>How can I use SAS to combine my variables to create a completely new variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620219#M19509</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have two variables in my dataset, pounds and Ounces. I am trying to combine these variables into a total weight variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if an observation has a recorded 8 pounds and a recorded 2 ounces, I want to create this new variable to say 8.2. Is this possible in SAS, and if so, how do I accomplish this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 16:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620219#M19509</guid>
      <dc:creator>SM8</dc:creator>
      <dc:date>2020-01-27T16:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use SAS to combine my variables to create a completely new variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620225#M19510</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299741"&gt;@SM8&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have two variables in my dataset, pounds and Ounces. I am trying to combine these variables into a total weight variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if an observation has a recorded 8 pounds and a recorded 2 ounces, I want to create this new variable to say 8.2. Is this possible in SAS, and if so, how do I accomplish this?&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;Be very careful of that sort of non-standard representation. If you want a decimal version you would be better off where 2 ounces is represented as 0.125 then you actually have unit for the variable in pounds:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newweight = pounds + ounces/16;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would be the way with a data step to convert ounces to pounds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would have to very clearly describe the actual advantage or use of storing the value as 8.2. You couldn't do substraction, such as determining change in weight, or look up with standard tables a value as you propose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps change the whole value to ounces? Newweight = pounds*16 + ounces;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dealt with some data that was provided in a form similar to what you propose only the "decimal" portion was fourths of a pound. And none of the uses wanted that sort of units so had to be converted to actual pounds before anything could be done.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 16:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620225#M19510</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-01-27T16:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use SAS to combine my variables to create a completely new variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620228#M19511</link>
      <description>&lt;P&gt;Yes it's possible. But do you really want 8.2 as 8 lbs and 2 ounces? Then you're deviating from the standard definition of the decimal value which is problematic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want that, try CATX().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_var = catx(".", put(pound, 8. -l), put(ounces, 8. -l));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A better approach is to store everything in one unit, ounces.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;weight_ounce_total = pound*16 + ounce;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299741"&gt;@SM8&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have two variables in my dataset, pounds and Ounces. I am trying to combine these variables into a total weight variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if an observation has a recorded 8 pounds and a recorded 2 ounces, I want to create this new variable to say 8.2. Is this possible in SAS, and if so, how do I accomplish this?&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 16:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620228#M19511</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-27T16:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use SAS to combine my variables to create a completely new variable?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620402#M19519</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299741"&gt;@SM8&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd convert this data asap into a metric unit (kg) stored in a single variable to allow for any sort of calculation and aggregation.&lt;/P&gt;
&lt;P&gt;If you must print pounds and ounces in reports then consider creating a format for it (you'd likely would need Proc FCMP and then create a format which calls the function).&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 04:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-use-SAS-to-combine-my-variables-to-create-a-completely/m-p/620402#M19519</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-28T04:16:01Z</dc:date>
    </item>
  </channel>
</rss>

