Hello
First of all, SAS is a fantastic data processing tool and once you understand some techniques and syntax you can do just about anthing.
There are many ways to do this in SAS. Unfortunately for the new SAS users all the methods will be challenging. The method below is something SAS calls "by group processing" and in my opinion this one of the most powerful data processing functions of SAS. It woul behoove you to throughly understand it. The SAS documentation does a good on this. Below are the link and navigation. The documentation can be difficult to navigate, but you'll get used to it after awhile.
Go to
http://support.sas.com/onlinedoc/913/docMainpage.jsp
On the menu go to Base SAS ->
SAS Language Reference: Concepts ->
DATA Step Concepts ->
BY-Group Processing in the DATA Step
Now for the Example
* Create a SAS Data Set;
data one;
length id_client date 8 connected $ 3;
input id_client date connected $;
Format date ddmmyy10.;
informat date ddmmyy10.;
datalines;
1 10-10-2007 Yes
1 10-11-2007 No
1 10-12-2007 Yes
2 08-10-2007 Yes
2 15-11-2007 Yes
2 20-12-2007 Yes
3 25-10-2007 Yes
3 30-10-2007 No
;
run;
* Sort by client and date;
proc sort data=one;
by id_client date;
run;
* This is an advanced technique for a SAS newbie, but it works;
data two;
set one;
by id_client; /* enables by group processing in which
SAS creates 2 boolean internal variables: 1) first.id_client = 1 for the first occurence of id_client, else=0
2) last.id_client= 1 for the last occurence of id_client, else=0
*/
retain number ; * the retain statements "retains" the previous value unless you specifically tell it not too;
if first.id_client=1 then number=0; /* for the occurence of id_client your counter is set to 0 */
if connected eq 'Yes' then number=number+1; /* once you see a Yes the counter is incremented by 1 */
run;
/* to see what the first. and last. automatic variables are doing, see this code */
/* for learning purpose of by group processing */
data WhatSASisDoing;
set one;
by id_client;
retain number;
first=first.id_client; /* SAS won't output internal/automatice variables unless you assign it to another variable */
last=last.id_client;
if first.id_client=1 then number=0; /* for the occurence of id_client your counter is set to 0 */
if connected eq 'Yes' then number=number+1; /* once you see a Yes the counter is incremented by 1 */
run;
-Darryl