<?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 constants and variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53835#M14897</link>
    <description>Suggest that you consider adding a DATA step PUTLOG statement to list your variables in the last DATA step -- this info should help explain the message you are getting from SAS.  Focus on the intercept variable values with each DATA step interation, using the PUTLOG below:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Tue, 14 Oct 2008 19:37:10 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2008-10-14T19:37:10Z</dc:date>
    <item>
      <title>problem with constants and variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53834#M14896</link>
      <description>consider the following code&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://rafb.net/p/b6EolO67.html" target="_blank"&gt;http://rafb.net/p/b6EolO67.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
it produces &lt;BR /&gt;
&lt;I&gt;&lt;BR /&gt;
                                              Obs    b&lt;BR /&gt;
                                               1     2&lt;BR /&gt;
                                               2     0&lt;BR /&gt;
                                               3     4&lt;BR /&gt;
&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
no problem what so ever.&lt;BR /&gt;
&lt;BR /&gt;
now consider this code&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://rafb.net/p/RQIrjE82.html" target="_blank"&gt;http://rafb.net/p/RQIrjE82.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
this code gives me some error saying "Missing values were generated as a result of performing an operation on missing values". it works when i write t = 2, but not with t = intercept. why?&lt;BR /&gt;
&lt;BR /&gt;
all i want to do is to multiply all the observations in x1 with the intercept (a constant) produced by the logistic procedure. &lt;BR /&gt;
&lt;BR /&gt;
why doesn't it work?</description>
      <pubDate>Tue, 14 Oct 2008 16:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53834#M14896</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-14T16:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: problem with constants and variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53835#M14897</link>
      <description>Suggest that you consider adding a DATA step PUTLOG statement to list your variables in the last DATA step -- this info should help explain the message you are getting from SAS.  Focus on the intercept variable values with each DATA step interation, using the PUTLOG below:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 14 Oct 2008 19:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53835#M14897</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-10-14T19:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: problem with constants and variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53836#M14898</link>
      <description>Hi:&lt;BR /&gt;
  Looking at your code, I'm confused by several things. So here are some comments that may help you get pointed in a direction. First, when I see code I MUST put clear step boundaries to separate the steps so I can check the SAS log between steps...the RUN; in caps is my addition to the code to separate the step boundaries and the comments with numbers are my annotation. Otherwise, this is the program from your second link:&lt;BR /&gt;
[pre]&lt;BR /&gt;
** 1) Create data set A with variables X1, X2, X3;&lt;BR /&gt;
data a;&lt;BR /&gt;
input x1 x2 x3;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 0 1&lt;BR /&gt;
0 1 1&lt;BR /&gt;
1 1 0&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
   &lt;BR /&gt;
** 2) Create data set B that is an exact copy of A;&lt;BR /&gt;
data b; set a;&lt;BR /&gt;
RUN;&lt;BR /&gt;
   &lt;BR /&gt;
** 3) run PROC LOGISTIC step using data set A as input;&lt;BR /&gt;
**     create an output data set  est_y1 from the LOGISTIC step;&lt;BR /&gt;
proc logistic data=a outest=est_y1;&lt;BR /&gt;
	model x1  = x2 x3/clparm=pl clodds=pl selection=backward;&lt;BR /&gt;
RUN;&lt;BR /&gt;
   &lt;BR /&gt;
** 4) Create data set X from est_y1 and A. This step has problems in that;&lt;BR /&gt;
**    variable B is not getting created as you wish;&lt;BR /&gt;
data x; set est_y1 a;&lt;BR /&gt;
t = intercept;&lt;BR /&gt;
b = x1*t;&lt;BR /&gt;
RUN;&lt;BR /&gt;
              &lt;BR /&gt;
** 5) print data set X and show only var B;&lt;BR /&gt;
proc print data = x; &lt;BR /&gt;
  var b;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
I would say that you have a program composed of 5 steps. I did not see any issues with Step 1 or Step 2. I do not understand the need for step 2 at all, since you never use data set B again.&lt;BR /&gt;
&lt;BR /&gt;
Step 3 is a Proc Logistic step and although it seems to work, I do get warnings in the log when I run your code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
275  proc logistic data=a outest=est_y1;&lt;BR /&gt;
276      model x1  = x2 x3/clparm=pl clodds=pl selection=backward;&lt;BR /&gt;
277  RUN;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: PROC LOGISTIC is modeling the probability that x1=0. One way to change this to model the probability that x1=1 is to specify&lt;BR /&gt;
      the response variable option EVENT='1'.&lt;BR /&gt;
WARNING: There is a complete separation of data points in Step 0. The maximum likelihood estimate does not exist.&lt;BR /&gt;
WARNING: The LOGISTIC procedure continues in spite of the above warning. Results shown are based on the last maximum likelihood&lt;BR /&gt;
         iteration. Validity of the model fit is questionable.&lt;BR /&gt;
WARNING: There is possibly a quasicomplete separation of data points in step 1. The maximum likelihood estimate may not exist.&lt;BR /&gt;
WARNING: The LOGISTIC procedure continues in spite of the above warning. Results shown are based on the last maximum likelihood&lt;BR /&gt;
         iteration. Validity of the model fit is questionable.&lt;BR /&gt;
 [/pre]&lt;BR /&gt;
&lt;BR /&gt;
However, assuming that you are comfortable with the warning, the output data set has one observation and looks like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs    _LINK_    _TYPE_     _STATUS_      _NAME_    Intercept    x2    x3    _LNLIKE_&lt;BR /&gt;
              &lt;BR /&gt;
 1     LOGIT     PARMS     0 Converged      x1       -0.69315     .     .    -1.90954&lt;BR /&gt;
            &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
It looks like in your step 4, you want to create the variable T from the INTERCEPT variable in the outest dataset EST_Y1. The issue comes in your step 4. If you look in the log after your version of step 4 runs:&lt;BR /&gt;
[pre]&lt;BR /&gt;
279  ** 4) Create data set X from est_y1 and A. This step has problems in that;&lt;BR /&gt;
280  **    variable B is not getting created as you wish;&lt;BR /&gt;
281  data x; set est_y1 a;&lt;BR /&gt;
282  t = intercept;&lt;BR /&gt;
283  b = x1*t;&lt;BR /&gt;
284  RUN;&lt;BR /&gt;
          &lt;BR /&gt;
NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;
      Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;
      4 at 283:7&lt;BR /&gt;
NOTE: There were 1 observations read from the data set WORK.EST_Y1.&lt;BR /&gt;
NOTE: There were 3 observations read from the data set WORK.A.&lt;BR /&gt;
NOTE: The data set WORK.X has 4 observations and 11 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
     &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
You see that missing values were created 4 times. If you follow Scott's advice and use the PUTLOG statement by modifying the program above -- you see this (only PUTLOG &amp;amp; PUTLOG output shown):&lt;BR /&gt;
[pre]&lt;BR /&gt;
                   &lt;BR /&gt;
PUTLOG _n_= intercept= x1= x2= x3= t= b=;&lt;BR /&gt;
           &lt;BR /&gt;
_N_=1 Intercept=-0.693147181 x1=. x2=. x3=. t=-0.693147181 b=.&lt;BR /&gt;
_N_=2 Intercept=. x1=1 x2=0 x3=1 t=. b=.&lt;BR /&gt;
_N_=3 Intercept=. x1=0 x2=1 x3=1 t=. b=.&lt;BR /&gt;
_N_=4 Intercept=. x1=1 x2=1 x3=0 t=. b=.&lt;BR /&gt;
               &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
What's happening is that when the data set being read is the EST_Y1 data set, then you have a value for INTERCEPT; however, when the program switches to read from data set A, then INTERCEPT is set to missing (just as X1, X2 and X3 are missing when reading from EST_Y1, but have values when reading from A). &lt;BR /&gt;
  &lt;BR /&gt;
  The way the data step works is that the "buffer" area that holds data set variables is reset or initialized to missing between each reading each row from the INPUT file. So what the PUTLOG reveals is that the WARNING Message is exactly correct...when you multiply any number by a missing value, the result is missing.&lt;BR /&gt;
&lt;BR /&gt;
  The reason that it works when you use a constant such as T=2; is that the assignment statement is EXECUTED for every iteration through the data step. So at the "top" of the program, T was missing, but for the assignment statement, T was set to 2. You can prove this to yourself by changing your first program to be as shown below:&lt;BR /&gt;
[pre]&lt;BR /&gt;
316  data b;&lt;BR /&gt;
317    set a;&lt;BR /&gt;
318    PUTLOG 'Top of DATA step:';&lt;BR /&gt;
319    PUTLOG _ALL_;&lt;BR /&gt;
320    t = 2;&lt;BR /&gt;
321    PUTLOG 'Before Calc B';&lt;BR /&gt;
322    PUTLOG _ALL_;&lt;BR /&gt;
323&lt;BR /&gt;
324    b = x1*t;&lt;BR /&gt;
325    PUTLOG 'Bottom of DATA step:';&lt;BR /&gt;
326    PUTLOG _ALL_;&lt;BR /&gt;
327&lt;BR /&gt;
328  RUN;&lt;BR /&gt;
              &lt;BR /&gt;
Top of DATA step:&lt;BR /&gt;
x1=1 t=. b=. _ERROR_=0 _N_=1&lt;BR /&gt;
Before Calc B&lt;BR /&gt;
x1=1 t=2 b=. _ERROR_=0 _N_=1&lt;BR /&gt;
Bottom of DATA step:&lt;BR /&gt;
x1=1 t=2 b=2 _ERROR_=0 _N_=1&lt;BR /&gt;
Top of DATA step:&lt;BR /&gt;
x1=0 t=. b=. _ERROR_=0 _N_=2&lt;BR /&gt;
Before Calc B&lt;BR /&gt;
x1=0 t=2 b=. _ERROR_=0 _N_=2&lt;BR /&gt;
Bottom of DATA step:&lt;BR /&gt;
x1=0 t=2 b=0 _ERROR_=0 _N_=2&lt;BR /&gt;
Top of DATA step:&lt;BR /&gt;
x1=2 t=. b=. _ERROR_=0 _N_=3&lt;BR /&gt;
Before Calc B&lt;BR /&gt;
x1=2 t=2 b=. _ERROR_=0 _N_=3&lt;BR /&gt;
Bottom of DATA step:&lt;BR /&gt;
x1=2 t=2 b=4 _ERROR_=0 _N_=3&lt;BR /&gt;
[/pre]&lt;BR /&gt;
    &lt;BR /&gt;
So, in order to fix your program #4, you have to do 2 things:&lt;BR /&gt;
1) you need to read EST_Y1 and RETAIN the INTERCEPT value when _N_ = 1&lt;BR /&gt;
and&lt;BR /&gt;
2) then you need a separate SET statement for data set A. &lt;BR /&gt;
Something like what's shown below:&lt;BR /&gt;
[pre]&lt;BR /&gt;
336  data x;&lt;BR /&gt;
337    retain intercept;&lt;BR /&gt;
338    if _n_ = 1 then set est_y1;&lt;BR /&gt;
339    set a;&lt;BR /&gt;
340    t = intercept;&lt;BR /&gt;
341    b = x1*t;&lt;BR /&gt;
342    PUTLOG _n_= intercept= x1= x2= x3= t= b=;&lt;BR /&gt;
343  RUN;&lt;BR /&gt;
               &lt;BR /&gt;
_N_=1 intercept=-0.693147181 x1=1 x2=0 x3=1 t=-0.693147181 b=-0.693147181&lt;BR /&gt;
_N_=2 intercept=-0.693147181 x1=0 x2=1 x3=1 t=-0.693147181 b=0&lt;BR /&gt;
_N_=3 intercept=-0.693147181 x1=1 x2=1 x3=0 t=-0.693147181 b=-0.693147181&lt;BR /&gt;
NOTE: There were 1 observations read from the data set WORK.EST_Y1.&lt;BR /&gt;
NOTE: There were 3 observations read from the data set WORK.A.&lt;BR /&gt;
NOTE: The data set WORK.X has 3 observations and 11 variables.&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
                &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
My suggestion is that you read the documentation on how the SET statement works and how the RETAIN statement works. You might also want to search the SAS documentation for a description of how the "PROGRAM DATA VECTOR" or PDV operates -- that's the buffer that gets reinitialized for every iteration through the data step program.&lt;BR /&gt;
&lt;BR /&gt;
 I'd also suggest that you drop step 2 completely from your code -- it's probably just a left over from your previous program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 15 Oct 2008 03:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53836#M14898</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-10-15T03:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: problem with constants and variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53837#M14899</link>
      <description>Thank you Cynthia for your thorough explanation!</description>
      <pubDate>Wed, 15 Oct 2008 23:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-with-constants-and-variables/m-p/53837#M14899</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-15T23:40:47Z</dc:date>
    </item>
  </channel>
</rss>

