- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-19-2010 03:57 PM
(1430 views)
I have a data set with many sas-date variables that represent dates on which certain events occured for each observation. If the event did not occur, the date variables are missing.
To count how many of the events occurred (and create a new variable with this information), I would simply use the N( var1, var2, varN...) function in a data step.
Now, if I need to count how many of these events occurred (i.e., how many variables have non-missing values) within a date range created by other variables, can I use the N function nested somehow in an if-then string? Is there another applicable function?
The data looks like this if my wording wasn't clear:
startdate enddate event1 event2 event3
4/12/98 5/15/98 4/14/98 5/26/98 4/30/98
And I need to find how many events happened between the startdate and enddate.
Thanks
To count how many of the events occurred (and create a new variable with this information), I would simply use the N( var1, var2, varN...) function in a data step.
Now, if I need to count how many of these events occurred (i.e., how many variables have non-missing values) within a date range created by other variables, can I use the N function nested somehow in an if-then string? Is there another applicable function?
The data looks like this if my wording wasn't clear:
startdate enddate event1 event2 event3
4/12/98 5/15/98 4/14/98 5/26/98 4/30/98
And I need to find how many events happened between the startdate and enddate.
Thanks
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You have the INTCK function to consider. Also, you may want to consider a DO/END loop to check for dates within a low/high range -- consider that SAS numeric DATE variables are represented as "number of days since 1/1/1960".
Also, if all analysis is done within one observation, you can look at using your appropriate function, like N, and code this type of assignment statement:
34 data _null_;
35 input (startdate enddate event1 event2 event3) (mmddyy8.);
36 format startdate enddate event: date9.;
37 occur = n(of event: );
38 putlog _infile_ / _all_;
39 datalines;
4/12/98 5/15/98 4/14/98 5/26/98 4/30/98
startdate=12APR1998 enddate=15MAY1998 event1=14APR1998 event2=26MAY1998 event3=30APR1998 occur=3
_ERROR_=0 _INFILE_=4/12/98 5/15/98 4/14/98 5/26/98 4/30/98 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
41 run;
Scott Barry
SBBWorks, Inc.
Also, if all analysis is done within one observation, you can look at using your appropriate function, like N, and code this type of assignment statement:
34 data _null_;
35 input (startdate enddate event1 event2 event3) (mmddyy8.);
36 format startdate enddate event: date9.;
37 occur = n(of event: );
38 putlog _infile_ / _all_;
39 datalines;
4/12/98 5/15/98 4/14/98 5/26/98 4/30/98
startdate=12APR1998 enddate=15MAY1998 event1=14APR1998 event2=26MAY1998 event3=30APR1998 occur=3
_ERROR_=0 _INFILE_=4/12/98 5/15/98 4/14/98 5/26/98 4/30/98 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
41 run;
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I finally buckled down and learned do loops. Thanks for the advice.
td
td