SAS exhaustion?

Reply
Occasional Contributor
Posts: 17

SAS exhaustion?

[ Edited ]

Greetings everyone,

 

So I noticed a weird behavior in SAS. By the end of intensive or long work sessions, the calculations sometimes get astray. Errors, unexpected negative signs, etc. If I restart the software, things fall into place. It doesn't sound right but it's happening, different laptops, different operating systems (different versions of Windows to be exact).  Restarting the laptop doesn't add much to this observation but I restart the whole thing anyway.

 

Any explanation, or a setting I need to adjust?

 

Thanks a lot.

 

P.S. I'm using SAS 9.4

 

Edit: It doesn't happen with a specific analysis. Happened with panel analysis, and with a simple addition of two variables. Also, it happens randomly on different projects with large data.

 

 

 

 

Respected Advisor
Posts: 2,797

Re: SAS exhuastion?

[ Edited ]

As we asked in a previous thread you created, we need to see the code and we need to see the data and an example of this "stray" calculation. Without that, it's impossible to provide any assistance.

--
Paige Miller
Occasional Contributor
Posts: 17

Re: SAS exhuastion?

Posted in reply to PaigeMiller

That's correct.

 

Here's the latest incident

 

Data test; 

set source;

If Workers <= 25 then Size = 1;

If (Workers > 25 AND Workers <= 50) then Size = 2;

If (Workers > 50 AND Workers <= 100) then Size = 3;

If (Workers > 100 AND Workers <= 200) then Size = 4;

If (Workers > 200 AND Workers <= 300) then Size = 5;

If (Workers > 300 AND Workers <= 400) then Size = 6;

If (Workers > 400 AND Workers <= 500) then Size = 7;

If (Workers > 500) then Size = 8;

 

Asset = Cash + Gold;

Transfer = Total - SUM(Cash, Gold);

AssetRatio = SUM(Cash, Gold)/Total;

TransferRatio = (Total - SUM(Cash, Gold))/Total;

 

Run;

 

 

When the error happened, the "Transfer" randomly carried negative signs, which doesn't make sense because it should all sum to the total. I almost called off the project before I remembered the alleged glitch, restarted the software, and voila! All is good.

 

I'm attaching a sample of the data for your convenience.

 

Thanks.

Attachment
Super User
Posts: 23,224

Re: SAS exhuastion?

What's your exact version of SAS? 9.4 TS1M3?

 

I had that yesterday...it confused the heck out of me. I had a query where it was working with single quotes but the exact same query wasn't working with double quotes.  After a restart it worked fine. 

 

No clue why it happens but definitely more when I'm writing/developing macros so I think it has more to do with an error or incorrect code causing an issue. 

Occasional Contributor
Posts: 17

Re: SAS exhuastion?

[ Edited ]

I'm using SAS 9.4 TS1M4

 

Well, I made a habit of periodically closing the software and launching it again before testing key changes to any code. You might find this helpful.

 

I'm inclined to put it on RAM management issue more than a code issue. For one, the thing works fine with the same code after the restart (without RAM congestion per the Task Manager). I previously thought it's a flaw in my old CPU, but now I'm using a totally different device from a different brand, yet the problem grinned at me again!

PROC Star
Posts: 2,307

Re: SAS exhuastion? Image cannot be added to the ImageList

>Well, I made a habit of periodically closing the software and launching it again before testing key changes to any code.

 

EG takes care of this for me. 

10 deaths in 2 days last time I counted.

"Epitaphs" are varied too: out of memory exception, Image cannot be added to the ImageList, cannot create file that already exists, failed to rename a lockfile. So many ways to be surprised...

Super User
Posts: 3,853

Re: SAS exhuastion?

Can you provide an example of the output data with the "randomly carried negative signs"? I'm assuming here that these numbers are much below zero and are not just slightly below zero as a result of data precision issues.

Occasional Contributor
Posts: 17

Re: SAS exhuastion?

Unfortunately, I did not save that output.  It was too erroneous for my project to keep.

 

To your other point, Nope. They were not 'much below zero'. They were the exact correct results yet with negative signs in random order across the observations of 'Transfer' in the abovementioned code.

 

For example, if the correct calculation is

 

334

567

789

908

 

Then that erroneous output would have been something like:

-334

567

789

-908

 

This example is not a copy of the error, but a demonstration of how it looked with the abovementioned code and data sample. Hope it helps.

 

 

Respected Advisor
Posts: 4,665

Re: SAS exhuastion?

@mragaa

I'm with @Reeza that the more likely cause that you're observing such issues is some "leftover from a previous run". When using clients like SAS EG then you're constantly using the same session with whatever you've already done previously still being part of the session. So it's a good idea to close and reconnect to the server from time to time. You don't have to close the client or even restart your computer - just reconnect to the server as this will create a brand new SAS session for you.

 

Using the code (see below) and data you've posted I've run 10000 iterations but couldn't replicate what you describe. The result was for me always the same as one would hope for.

options nonotes nosource nomprint;
libname source 'c:\temp';

%macro test(iter);
  %do i=1 %to &iter;
    data test_&i; 
      set source.sample;
      if workers <= 25 then size = 1;
      if (workers > 25 and workers <= 50) then size = 2;
      if (workers > 50 and workers <= 100) then size = 3;
      if (workers > 100 and workers <= 200) then size = 4;
      if (workers > 200 and workers <= 300) then size = 5;
      if (workers > 300 and workers <= 400) then size = 6;
      if (workers > 400 and workers <= 500) then size = 7;
      if (workers > 500) then size = 8;

      asset = cash + gold;
      transfer = total - sum(cash, gold);
      assetratio = sum(cash, gold)/total;
      transferratio = (total - sum(cash, gold))/total;
    run;

    %if &i ne 1 %then
      %do;
        proc compare data=test_%eval(&i-1) compare=test_&i out=work.diff outnoequal noprint;
        run;
        
        data _null_;
          call symputx('nobs',nobs);
          stop;
          set work.diff nobs=nobs;
        run;

        %if &nobs>0 %then
          %do;
            data diff;
              ds1="test_%eval(&i-1)";
              ds2="test_&i";
              set diff;
            run;
            proc print data=diff;
            run;
            %let i=%eval(&iter+1); 
          %end;
        %else
          %do;
            proc delete data=test_%eval(&i-1);
            run;
          %end;

      %end;

  %end;
  

%mend;

%test(10000);
Occasional Contributor
Posts: 17

Re: SAS exhuastion?

Thanks a lot. I appreciate you all taking the time and brain cycles through this.

 

Probably I misread Reeza's point (sorry Reeza).  Yes, 'left over' seems to be the word.

 

OK, I guess we all boil it down to making fresh sessions a habit.

 

Thank you again, everyone.

 

Respected Advisor
Posts: 4,665

Re: SAS exhuastion?

[ Edited ]

@mragaa

On a side note in regards of the code you've posted: If you're coding a set of selections where only one of the conditions may be True then consider using the ELSE statement as then SAS will stop testing as soon as a condition becomes True. 

The code for this would look like:

data test; 
  set source.sample;
  if workers <= 25 then size = 1;
  ELSE if (workers > 25 and workers <= 50) then size = 2;
  ELSE if (workers > 50 and workers <= 100) then size = 3;
  ELSE if (workers > 100 and workers <= 200) then size = 4;
  ELSE if (workers > 200 and workers <= 300) then size = 5;
  ELSE if (workers > 300 and workers <= 400) then size = 6;
  ELSE if (workers > 400 and workers <= 500) then size = 7;
  ELSE if (workers > 500) then size = 8;

  asset = cash + gold;
  transfer = total - sum(cash, gold);
  assetratio = sum(cash, gold)/total;
  transferratio = (total - sum(cash, gold))/total;
run;

Another option is to use Formats and Informats which are a very powerful alternative method to get such recoding done.


proc format;
  invalue workerSize
     low - 25   = 1
     25 - 50    = 2
     50 - 100   = 3
     100 - 200  = 4
     200 - 300  = 5
     300 - 400  = 6
     400 - 500  = 7
     500 - high = 8
  ;
run;

data test2;
  set source.sample;
  size=input(workers,workerSize.);

  asset = cash + gold;
  transfer = total - sum(cash, gold);
  assetratio = sum(cash, gold)/total;
  transferratio = (total - sum(cash, gold))/total;
run;

 

Occasional Contributor
Posts: 17

Re: SAS exhuastion?

@Patrick

 

Wow!  This is a completely new one for me. I honestly cannot describe enough how I appreciate your advice; let alone that it went beyond the uneducated limitations of my initial question.  Thank you. My respects!

Occasional Contributor
Posts: 11

Re: SAS exhuastion?

Hi mragaa,

 

     If indeed it is a leftover, which I suspect too, I'd recommend you try to understand what is really causing it. This may "haunt" you in the future when you start writing more complex programs. Personally, I've never had the opportunity to find a bug in data step, and I wrote a lot of "fancy" stuff with it.

 

     But if you think you really found a bug in data step, please document the way to reproduce it and get in touch with SAS Support. We'll all be thankful to you if you do so!

 

Thanks!

Ask a Question
Discussion stats
  • 12 replies
  • 1161 views
  • 11 likes
  • 7 in conversation