BookmarkSubscribeRSS Feed
GKT
Calcite | Level 5 GKT
Calcite | Level 5

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

 

 

7 REPLIES 7
GKT
Calcite | Level 5 GKT
Calcite | Level 5

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)

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

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

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

ballardw
Super User

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.

 

GKT
Calcite | Level 5 GKT
Calcite | Level 5

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.

 

 

FreelanceReinh
Jade | Level 19

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)?
GKT
Calcite | Level 5 GKT
Calcite | Level 5

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)

 

FreelanceReinh
Jade | Level 19

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).

GKT
Calcite | Level 5 GKT
Calcite | Level 5

Thank YOU Soooooooooo Much!!! It worked like a charm! 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 925 views
  • 0 likes
  • 3 in conversation