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

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!

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.

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
  • 1 reply
  • 590 views
  • 0 likes
  • 2 in conversation