<?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: initializing variable in retain statement in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478165#M5906</link>
    <description>&lt;P&gt;Reinhardt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included the code and the log. I modified as per your suggestion but it does not give me any obs as seen in the log. SInce i am dividing in the last step I wanted data without any zeros or miss val. all the 3 data sets have the values.&lt;/P&gt;&lt;P&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;data totalteachers (keep = School County Teachers);&lt;BR /&gt;set impute_mid_schools impute_high_schools;&lt;BR /&gt;Total_Teachers=sum(of Teacher_mid Teacher_high);&lt;BR /&gt;Teachers =ceil(Total_Teachers);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;data totalstudentsgrd7togrd12;&lt;BR /&gt;set impute_mid_schools impute_high_schools totalteachers;&lt;BR /&gt;if Teacher_mid&amp;gt;0 and Teacher_high&amp;gt;0;&lt;BR /&gt;Total_Students_grd7togrd12=sum(of mid_Grd7-mid_Grd12)+sum(of hs_Grd7-hs_Grd12);&lt;BR /&gt;retain PTRatio_rev 0;&lt;BR /&gt;PTRatio_rev=Total_Students_grd7togrd12/Teachers;&lt;BR /&gt;format PTRatio_rev 9.2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;log&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 610 observations read from the data set WORK.IMPUTE_MID_SCHOOLS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 459 observations read from the data set WORK.IMPUTE_HIGH_SCHOOLS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 1069 observations read from the data set WORK.TOTALTEACHERS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.TOTALSTUDENTSGRD7TOGRD12 has 0 observations and 24 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 15 Jul 2018 00:14:14 GMT</pubDate>
    <dc:creator>savannah</dc:creator>
    <dc:date>2018-07-15T00:14:14Z</dc:date>
    <item>
      <title>initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478096#M5902</link>
      <description>&lt;DIV class="sasSource"&gt;How can I initalize the variable in the last steps? I do not get any observations as it shows an error..variables not initialized.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;data totalstudentsgrd7togrd12;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;set impute_mid_schools impute_high_schools;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;if Teacher_mid&amp;gt;0 and Teacher_high&amp;gt;0;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;retain set impute_mid_schools impute_high_schools 0;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;retain PTRatio_rev 0;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;Total_Students_grd7togrd12=sum(of mid_Grd7-mid_Grd12)+sum(of hs_Grd7-hs_Grd12);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;PTRatio_rev=Total_Students_grd7togrd12/Teachers;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;format Revised PTRatio 9.2;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;run;&lt;/DIV&gt;</description>
      <pubDate>Sat, 14 Jul 2018 06:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478096#M5902</guid>
      <dc:creator>savannah</dc:creator>
      <dc:date>2018-07-14T06:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478097#M5903</link>
      <description>&lt;P&gt;Please post your log? Also, please post an example of what your data looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Makes it so much easier to help you&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 06:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478097#M5903</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-07-14T06:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478099#M5904</link>
      <description>&lt;P&gt;"uninitialised" can be something as simple as a typo, for example you refer to variable "PTRatio" in a format statement but it is not defined anywhere, that would surely lead to "PTRatio is uninitialised" comment in the log. But you should specify which variable the log indicates is the problem&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 07:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478099#M5904</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-07-14T07:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478102#M5905</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220810"&gt;@savannah&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV class="sasSource"&gt;I do not get any observations ...&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;data totalstudentsgrd7togrd12;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;set impute_mid_schools impute_high_schools;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;if Teacher_mid&amp;gt;0 and Teacher_high&amp;gt;0;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please note that the above subsetting IF statement will indeed block out all observations if Teacher_mid is a variable in impute_mid_schools (but not in &lt;SPAN&gt;impute_high_schools)&amp;nbsp;&lt;/SPAN&gt;and&amp;nbsp;&lt;SPAN&gt;Teacher_high is a variable in impute_high_schools (but not in&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;impute_mid_schools).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220810"&gt;@savannah&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV class="sasSource"&gt;... variables not initialized.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The number of uninitialized variables will decrease as soon as you delete the line where you seem to combine a RETAIN and a SET statement (but in fact create an uninitialized variable named SET among others) and correct the&amp;nbsp;FORMAT statement to&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format PTRatio_rev 9.2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;("Revised PTRatio" is probably the &lt;EM&gt;label&lt;/EM&gt; of variable PTRatio_rev.)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 09:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478102#M5905</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-07-14T09:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478165#M5906</link>
      <description>&lt;P&gt;Reinhardt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included the code and the log. I modified as per your suggestion but it does not give me any obs as seen in the log. SInce i am dividing in the last step I wanted data without any zeros or miss val. all the 3 data sets have the values.&lt;/P&gt;&lt;P&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;data totalteachers (keep = School County Teachers);&lt;BR /&gt;set impute_mid_schools impute_high_schools;&lt;BR /&gt;Total_Teachers=sum(of Teacher_mid Teacher_high);&lt;BR /&gt;Teachers =ceil(Total_Teachers);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;data totalstudentsgrd7togrd12;&lt;BR /&gt;set impute_mid_schools impute_high_schools totalteachers;&lt;BR /&gt;if Teacher_mid&amp;gt;0 and Teacher_high&amp;gt;0;&lt;BR /&gt;Total_Students_grd7togrd12=sum(of mid_Grd7-mid_Grd12)+sum(of hs_Grd7-hs_Grd12);&lt;BR /&gt;retain PTRatio_rev 0;&lt;BR /&gt;PTRatio_rev=Total_Students_grd7togrd12/Teachers;&lt;BR /&gt;format PTRatio_rev 9.2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;log&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 610 observations read from the data set WORK.IMPUTE_MID_SCHOOLS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 459 observations read from the data set WORK.IMPUTE_HIGH_SCHOOLS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: There were 1069 observations read from the data set WORK.TOTALTEACHERS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: The data set WORK.TOTALSTUDENTSGRD7TOGRD12 has 0 observations and 24 variables.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 00:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478165#M5906</guid>
      <dc:creator>savannah</dc:creator>
      <dc:date>2018-07-15T00:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478166#M5907</link>
      <description>&lt;P&gt;Reinhardt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was missing a then...if....then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i got the following log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;Missing values were generated as a result of performing an operation on missing values.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;1528 at 74:29 2138 at 74:55 1679 at 74:56 2138 at 76:40&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;There were 610 observations read from the data set WORK.IMPUTE_MID_SCHOOLS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;There were 459 observations read from the data set WORK.IMPUTE_HIGH_SCHOOLS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;There were 1069 observations read from the data set WORK.TOTALTEACHERS.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;The data set WORK.TOTALSTUDENTSGRD7TOGRD12 has 2138 observations and 24 variables.&lt;/DIV&gt;</description>
      <pubDate>Sun, 15 Jul 2018 00:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478166#M5907</guid>
      <dc:creator>savannah</dc:creator>
      <dc:date>2018-07-15T00:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: initializing variable in retain statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478198#M5910</link>
      <description>&lt;P&gt;Without having sample data this is a bit like detective work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The missing values mentioned in the log&amp;nbsp;can be explained as follows:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The six variables mid_Grd7-mid_Grd12 are all missing for the 459 observations from dataset IMPUTE_HIGH_SCHOOLS. Most probably they are simply not contained in that dataset.&lt;/LI&gt;
&lt;LI&gt;The six variables hs_Grd7-hs_Grd12 are all missing for the 610 observations from dataset IMPUTE_MID_SCHOOLS. Again, most probably they are not contained in that dataset.&lt;/LI&gt;
&lt;LI&gt;Certainly, none of the above 12 variables is contained in dataset TOTALTEACHERS (which contains only School, County and Teachers) with its 1069 observations.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;That's why you get (in "line 74" of the log):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;459+1069=1528 missing values for sum(of mid_Grd7-mid_Grd12)&lt;/LI&gt;
&lt;LI&gt;610+1069=1679 missing values for sum(of hs_Grd7-hs_Grd12)&lt;/LI&gt;
&lt;LI&gt;459+610+1069=2138 missing values, i.e. &lt;EM&gt;only&lt;/EM&gt; missing values, for variable Total_Students_grd7togrd12.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;This last fact in turn explains the 2138 missing values you obtain for variable PTRatio_rev in "line 76" (by dividing missing values by values of variable Teachers, many of which are most likely also missing, because only dataset TOTALTEACHERS can be reasonably expected to contain this variable according to your first data step).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, merely &lt;EM&gt;concatenating&lt;/EM&gt; the three datasets with the SET statement does not create a suitable basis for your calculations. Here is an instructive example of what happened in your program:&amp;nbsp;&lt;A href="http://documentation.sas.com/?docsetId=basess&amp;amp;docsetTarget=n0njwz9w8z3ayon1neo3mkc9e9gg.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n13iocrnjd0811n0zhn83cmhrqki" target="_blank"&gt;Using the SET Statement When Data Sets Contain Different Variables&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need more help, please post a few lines of sample data (for each of the three datasets involved) in the form of a datastep (see &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="_blank"&gt;instructions&lt;/A&gt;) and describe what you want as output.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 13:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/initializing-variable-in-retain-statement/m-p/478198#M5910</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-07-15T13:00:08Z</dc:date>
    </item>
  </channel>
</rss>

