Programming the statistical procedures from SAS

Re: How can I measure the exact time from data with SAS

Reply
Occasional Contributor
Posts: 16

Re: How can I measure the exact time from data with SAS

Hi

My name is woo.

and I'm having problem with my research so I need some tips from SAS professional who are familliar with this problem.

I really want to measure exact time of Wifi Use.

And data is as follows...

Connected 0 represents Wifi is disconnected

and 1 represents Wifi is connected

prob1.png

At first, I thought it was very easy and I wrote some code like this;

DATA Wifi_status;

INFILE "D:\research\Wifi_Status_august.csv" dlm="," LRECL=300  TRUNCOVER firstobs=2;

INPUT UserId :$20. Clientkey :$1. Time :anydtdtm19. Connected IsOpen ;

keep Userid Time Connected;

run;

Proc sort data=Wifi_status; by userid time; run;

data Wifi_status1;

set Wifi_status; if connected=1;

Starttime=Time;

connected1=connected;

keep userid Starttime
connected1;
run;

proc sort data=Wifi_status1; by userid Starttime; run;

data Wifi_status2;

set Wifi_status; if connected=0;

Endtime=Time;

connected0=connected;

keep userid Endtime
connected0;
run;

proc sort data=Wifi_status2; by userid Endtime; run;

Data Wifi_status0;

merge Wifi_status1 Wifi_status2;

Wifi_sec=endtime-starttime;

Wifi_min=(Wifi_sec)/60;

run;

But, there's some mistakes or erros in the data like sequencing 0000 or 111.

So, My result is totally crabbed..

like this

pro2.png

I want to leave out some faults in my data How can I leave them out?

Please give me some your generous tips.

Thanks

Super Contributor
Posts: 543

Re: How can I measure the exact time from data with SAS

Hi.

Some sample data to work with would help,

but I would first suggest that instead of taking the variable "TIME" as is, I would first strip the date out of the "TIME" variable, thus obtaining the hour and minutes.

So, say, you have time = 2012-08-01 8:49, what you really want is a way to strip the time from the date.

BUT

you need to also keep a count for the date (so if one is connected for 2 days and four hours, you actually count the days as well).

Please provide some sample data.

Thanks.

Occasional Contributor
Posts: 16

Re: How can I measure the exact time from data with SAS

Thanks for your advice.

But, How can I extract the days from My 'Time' Variable..

ps. I can email you sample file

Super User
Posts: 10,801

Re: How can I measure the exact time from data with SAS

After your sort I would try

proc means data=WiFi_status;

     class userid;

     by connected notsorted;

     var time;

     output out=usertime max= min= range=/autoname;

run;

The output dataset should have a record for each contiguous period of time connected and not connected. The range is what you want but the units aren't going to be obvious, the max and min will show per period as well.

Occasional Contributor
Posts: 16

Re: How can I measure the exact time from data with SAS

Well;

I followed your code and SAS told me "Warning : Obsessive Print Size! "

Thanks for the advice but, it won't work

Super Contributor
Posts: 543

Re: How can I measure the exact time from data with SAS

Hi.

You can use the DAY function from SAS.

day_part = day(time_variable);

You could attach a sample data (say 10 observations max, and make sure you de-identify the data)

Good luck.

Ask a Question
Discussion stats
  • 5 replies
  • 226 views
  • 0 likes
  • 3 in conversation