Help using Base SAS procedures

Array Question?

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

Array Question?

hi team,

in the past i had a similar question and Tom &others helped me .

That time it was transposing the below "have" dataset into a single record. But now i want the below data to transposed into WANT dataset  having the 5 records like shown!!!

Thanks

/*aFTER SORTING MY DATASET BY :iD AND TIME I GET THE BELOW

"have"*/

ID      flag                        time         
101      TIMEIN     04SEP89:07:30:00   
101      TIMEIN     04SEP89:13:45:00  
101      TIMEOUT    05SEP89:07:15:00    
101      TIMEIN     21SEP89:17:55:00 
101      TIMEOUT    22SEP89:06:00:00
101      TIMEOUT    23SEP89:06:00:00
101      TIMEIN     24SEP89:06:00:00

/*WANT*/

ID                 timein                       timeout       
101           04SEP89:07:30:00          .  
101           04SEP89:13:45:00    05SEP89:07:15:00
101           21SEP89:17:55:00    22SEP89:06:00:00
101                 .                           23SEP89:06:00:00
101           24SEP89:06:00:00           .


Accepted Solutions
Solution
‎09-16-2013 01:34 PM
Respected Advisor
Posts: 3,799

Re: Array Question?

Posted in reply to robertrao

Seems like the main issue is how to group the in/out so that you can transpose.  This is what I came up with but it may not work for anything but your test data.

data stay;
   input ID $  flag $ time :datetime.;
  
format time datetime.;
  
cards;
101      TIMEIN     04SEP89:07:30:00   
101      TIMEIN     04SEP89:13:45:00  
101      TIMEOUT    05SEP89:07:15:00    
101      TIMEIN     21SEP89:17:55:00 
101      TIMEOUT    22SEP89:06:00:00
101      TIMEOUT    23SEP89:06:00:00
101      TIMEIN     24SEP89:06:00:00
;;;;
  run;
proc print;
 
run;
data stay2;
   set stay;
   by id flag notsorted;
  
if flag eq 'TIMEIN' then stay+1;
  
if not first.flag and flag eq 'TIMEOUT' then stay+1;
  
run;
proc print;
  
run;
proc transpose out=stay3;
   by id stay;
   id flag;
   var time;
   run;
proc print;
  
run;

View solution in original post


All Replies
Solution
‎09-16-2013 01:34 PM
Respected Advisor
Posts: 3,799

Re: Array Question?

Posted in reply to robertrao

Seems like the main issue is how to group the in/out so that you can transpose.  This is what I came up with but it may not work for anything but your test data.

data stay;
   input ID $  flag $ time :datetime.;
  
format time datetime.;
  
cards;
101      TIMEIN     04SEP89:07:30:00   
101      TIMEIN     04SEP89:13:45:00  
101      TIMEOUT    05SEP89:07:15:00    
101      TIMEIN     21SEP89:17:55:00 
101      TIMEOUT    22SEP89:06:00:00
101      TIMEOUT    23SEP89:06:00:00
101      TIMEIN     24SEP89:06:00:00
;;;;
  run;
proc print;
 
run;
data stay2;
   set stay;
   by id flag notsorted;
  
if flag eq 'TIMEIN' then stay+1;
  
if not first.flag and flag eq 'TIMEOUT' then stay+1;
  
run;
proc print;
  
run;
proc transpose out=stay3;
   by id stay;
   id flag;
   var time;
   run;
proc print;
  
run;
Super Contributor
Posts: 1,041

Re: Array Question?

Posted in reply to data_null__

Thanks for the reply data_null_.

But why would it not work out of my test data?

Thanks

Respected Advisor
Posts: 3,799

Re: Array Question?

Posted in reply to robertrao

I said it MAY not.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 197 views
  • 1 like
  • 2 in conversation