DATA Step, Macro, Functions and more

ps -ef output report

Reply
Occasional Contributor GKT
Occasional Contributor
Posts: 5

ps -ef output report

Friends,

 

I am new to SAS programming.

 

I have a task to create the following report from ps-ef output on AIX. Each hour how many new Zombies created, died and remaining.

Server_Name           Date     Time      +NewZombies  -ZombiesDied   TotalZombies

Srv1                           Oct1      00:00              7                             3                        4

Srv2                           Oct1      01:00              2                             3                        3   (4 from prior hour + 2 new – 3 died = 3 remaining)

 

This is how my data looks like:

Server_Name    PID       Date           Proc_Start_hour   Proc_End_hour

Srv1                       1         Oct1                        0                               9
Srv1                       2         Oct1                        1                               2
Srv1                       3         Oct1                        2                               23
Srv1                       4         Oct1                        4                               4

 


Please give me logic/ideas to create the above report with the data i have.  Really appriciate any help here.

 

Thanks

Gopal

 

 

Occasional Contributor GKT
Occasional Contributor
Posts: 5

Re: ps -ef output report

correction:

 

with the sample data i want my final report to looks like this.

 

Server_Name           Date     Time      +NewZombies  -ZombiesDied   TotalZombies

Srv1                           Oct1      00:00              1                             0                        1

Srv2                           Oct1      01:00              1                             0                        2   (1 from prior hour + 1 new – 0 died = 2 remaining)

Srv2                           Oct1      02:00              1                             1                        2   (2 from prior hour + 1 new – 1 died = 2 remaining)

Srv2                           Oct1      03:00              1                             0                        3   (2 from prior hour + 1 new – 0 died = 3 remaining)

............................

............................

.............................

Super User
Posts: 11,343

Re: ps -ef output report

It looks like something like this is a start:

data want;
   set have;
   retain totalzombies 0;
   totalzombies = sum(totalz, newzombies, -1*zombiesDied);
run;

I used sum in case any of your newzombies or zombiesdied variables are missing values.

 

Occasional Contributor GKT
Occasional Contributor
Posts: 5

Re: ps -ef output report

Thank you,

 

but in my data Zombies died variable is not htere and i have to track the PID and subtract it in the hour it died.

 

 

Trusted Advisor
Posts: 1,118

Re: ps -ef output report

I think it would help if you could clarify your example and requirements a little more.

 

  1. Your data consists of four records with Server_Name='Srv1'. In your sample report, however, some rows have 'Srv2'.
  2. Are processes to be counted for each server (i.e. value of Server_Name) separately?
  3. Doesn't the fourth row of the sample report indicate that in hour 3 one process started? I cannot see that process in your data.
  4. Or should '03:00' in the report read '04:00', i.e., are only hours with new or died zombies to be included in the report? If so, how is the end hour of PID 4 reflected in the report (assuming that this process started and ended in the same hour)?
  5. Are all Proc_End_hour values non-missing (i.e. have ongoing processes been excluded already from the ps -ef output)?
  6. Isn't it possible that start date and end date of a process are different? How would this be reflected in the data?
  7. Would the solution have to detect the turn of the year (date Dec31 --> Jan1)?
Occasional Contributor GKT
Occasional Contributor
Posts: 5

Re: ps -ef output report

Posted in reply to FreelanceReinhard

FreelanceReinhard,

Thank you for your feedback/questions.  Sorry for the typos.  as i can not post the original data, i typed in a hurry.  To start with we are analyzing data within a day/date. If process runs for more than a day then we ignore that process for now. Basically this report is only for a single date.

following is the corrected report format and data:

This is how my data looks like:

Server                  PID       Date           Proc_Start_hour   Proc_End_hour

Srv1                       1         Oct1                        0                               9

Srv1                       2         Oct1                        1                               2

Srv1                       3         Oct1                        2                               23

Srv1                       4         Oct1                        3                               11

Srv1                       5         Oct1                        4                               4

Srv1                       6         Oct1                        5                               22

 

This is the expected report format:

Server    Date     Time      +NewZombies  -ZombiesDied   TotalZombies

Srv1        Oct1      00:00              1                             0                   ​     1

Srv1        Oct1      01:00              1                   ​          0                        2   (1 from prior hour + 1 new – 0 died = 2 remaining)

Srv1        Oct1      02:00              1                   ​          1                        2   (2 from prior hour + 1 new – 1 died = 2 remaining)

Srv1        Oct1      03:00              1                   ​          0                        3   (2 from prior hour + 1 new – 0 died = 3 remaining)

Srv1        Oct1      04:00              1                   ​          0                        3   (3 from prior hour + 1 new –1 died = 3 remaining)

Srv1        Oct1      05:00              1                   ​          0                        4   (3 from prior hour + 1 new – 0 died = 4 remaining)

 

Trusted Advisor
Posts: 1,118

Re: ps -ef output report

Try this:

data have;
input Server $ PID Date $ Proc_Start_hour Proc_End_hour;
cards;
Srv1 1 Oct1 0 9
Srv1 2 Oct1 1 2
Srv1 3 Oct1 2 23
Srv1 4 Oct1 3 11
Srv1 5 Oct1 4 4
Srv1 6 Oct1 5 22
;

proc sql;
create table temp as
select Server, Date, t*3600 as Time format=time5.,
       sum(a.t=b.proc_start_hour) as new  label='+NewZombies',
       sum(a.t=b.proc_end_hour)   as died label='-ZombiesDied'
from (select proc_start_hour as t from have
      union
      select proc_end_hour as t from have) a,
      have b
where a.t=b.proc_start_hour | a.t=b.proc_end_hour
group by Server, Date, Time
order by Server, Date, Time;
quit;

data want;
set temp;
by Server Date Time;
if first.date then total=0;
total+(new-died);
label total='TotalZombies';
run;

proc print data=want label;
run;

Please note that for Time=04:00 one zombie died.

 

This solution should work also for several servers and dates (where the dates would not be sorted in chronological order, though).

Occasional Contributor GKT
Occasional Contributor
Posts: 5

Re: ps -ef output report

Posted in reply to FreelanceReinhard

Thank YOU Soooooooooo Much!!! It worked like a charm! :-)

Ask a Question
Discussion stats
  • 7 replies
  • 288 views
  • 0 likes
  • 3 in conversation