BookmarkSubscribeRSS Feed
PCrider
Calcite | Level 5
I have a dataset concerning logins and logouts on a computer. The problem with the dataset is that there is not an equal amount of logins and logouts. (i.e. one person logged in and never logged out, or a different person logged out twice and never had a login, etc)

I have separated the set into 2 datasets, one for logins, one for logouts. Now I want to put the two back together grouping by each person, but adding a new observation if a login or a logout is missing that includes all the other variables.

ex:

OUT joe34 comp1 Mon. 2:25:45
OUT bob56 comp3 Mon. 3:45:24
IN dav87 comp2 Tues. 7:13:32
OUT dav87 comp2 Tues. 7:25:55
OUT sam78 comp2 Fri. 1:36:11
IN jak22 comp5 Sat. 12:24:32

So, I want each person to have 2 observations, one with IN etc... and the next with OUT etc...

Any ideas?
1 REPLY 1
Ksharp
Super User
OK. That is not too complicated!
[pre]





data temp;
input log $ name $ comp $ dt & $20.;
datalines;
OUT joe34 comp1 Mon. 2:25:45
OUT bob56 comp3 Mon. 3:45:24
IN dav87 comp2 Tues. 7:13:32
OUT dav87 comp2 Tues. 7:25:55
OUT sam78 comp2 Fri. 1:36:11
IN jak22 comp5 Sat. 12:24:32
;
run;
[/pre]
proc sql;



 create table _temp as



  select *



   from (select distinct
log
from temp),(select distinct

name
from temp)



    order by log,name;



quit;



proc sort data=temp;



 by log name;



run;



data _result;



 merge temp _temp;



 by log name;



run;



proc sort data=_result;



 by name;



run;



data result;



 merge _result(keep=log name)



       _result(keep=name comp dt

where=(comp is not missing or dt is not missing));



 by name;



run;
[pre]



[/pre]


Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 908 views
  • 0 likes
  • 2 in conversation