<?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: Problem with dividing a variable by a constant to create a new variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692155#M79681</link>
    <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the &amp;lt;&amp;gt; to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you say that you started with two dates you might investigate the INTCK function for returning intervals between dates as well, which I would do at the same time that you calculate the age in days.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Oct 2020 15:54:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-10-16T15:54:56Z</dc:date>
    <item>
      <title>Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692152#M79679</link>
      <description>&lt;P&gt;Good day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable that I calculated, which is "age" in days, by substracting two dates, giving me the value in days (variable called age, no problem).&amp;nbsp; I now want to take that variable and create a new variable which will be age in months (so divide by 30.5).&amp;nbsp; Here is my proc sql code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table work.data_want as&lt;BR /&gt;select *,&lt;/P&gt;&lt;P&gt;/* age_months */&lt;BR /&gt;(t1.age / 30.5) as age_months&lt;BR /&gt;from work.data_have t1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is very straightforward, but for some reason it does not want to work?&amp;nbsp; I also tried a IFN function, to no avail.&amp;nbsp; Nowhere do I get a error message.&amp;nbsp; The new variable (column) is created, but only has missing values in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help?&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 15:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692152#M79679</guid>
      <dc:creator>mvniekerk</dc:creator>
      <dc:date>2020-10-16T15:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692155#M79681</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the &amp;lt;&amp;gt; to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you say that you started with two dates you might investigate the INTCK function for returning intervals between dates as well, which I would do at the same time that you calculate the age in days.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 15:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692155#M79681</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-16T15:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692156#M79682</link>
      <description>&lt;P&gt;You said you calculated AGE_MONTHS this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(t1.age / 30.5) as age_months&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If AGE_MONTHS is missing for every observation then AGE must have been missing.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 16:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692156#M79682</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-16T16:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692179#M79685</link>
      <description>&lt;P&gt;Tom&lt;BR /&gt;It does calculate it, age in days and age in months. But for some reason if I move the column age_months, and write it to a .txt file (as I always do), it delete all the values so that there is only missing values. This is very strange to me?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 17:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692179#M79685</guid>
      <dc:creator>mvniekerk</dc:creator>
      <dc:date>2020-10-16T17:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692184#M79686</link>
      <description>Are you pointing to your original data set or your newly created data set with the age variable?</description>
      <pubDate>Fri, 16 Oct 2020 17:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692184#M79686</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-16T17:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692190#M79687</link>
      <description>&lt;P&gt;To the newly created dataset.&amp;nbsp; If I move the position of the column with the newly created age_months variable to another position, from the last column where it was created, to a column position earlier in the dataset, it delete all the values so that they are missing.&amp;nbsp; In other words, in every proc sql I do, I create a new variable (column).&amp;nbsp; Then at the end I want my dataset with the columns in a certain order.&amp;nbsp; When I shift that age_months column is when the aforementioned problem occurs?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 17:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692190#M79687</guid>
      <dc:creator>mvniekerk</dc:creator>
      <dc:date>2020-10-16T17:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692196#M79688</link>
      <description>Show your full code and log. What you think is happening isn't happening somewhere but we can't see what without seeing the actual code and log.</description>
      <pubDate>Fri, 16 Oct 2020 17:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692196#M79688</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-16T17:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692197#M79689</link>
      <description>&lt;P&gt;You cannot have two variables with the same name in a dataset.&amp;nbsp; If you select two or more variables with the same name then PROC SQL will keep only the first one.&lt;/P&gt;
&lt;P&gt;So if you do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table step2 as
select *, age/30.5 as age_months
from step1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And STEP1 already had a variable named AGE_MONTHS then the calculated value is discarded because there is not place to save it.&lt;/P&gt;
&lt;P&gt;Try like this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table step2 as
select *, age/30.5 as age_months
from step1(drop=age_months)
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Oct 2020 17:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692197#M79689</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-16T17:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dividing a variable by a constant to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692294#M79692</link>
      <description>&lt;P&gt;Thank you very much Tom.&amp;nbsp; You are correct!&amp;nbsp; Problem solved.&amp;nbsp; I see SAS is very sensitive in that way.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Oct 2020 11:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-dividing-a-variable-by-a-constant-to-create-a-new/m-p/692294#M79692</guid>
      <dc:creator>mvniekerk</dc:creator>
      <dc:date>2020-10-17T11:56:11Z</dc:date>
    </item>
  </channel>
</rss>

