BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
I finally buckled down and learned do loops. Thanks for the advice.

td

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1174 views
  • 0 likes
  • 2 in conversation