BookmarkSubscribeRSS Feed
Yennie
Calcite | Level 5
hey all,

i have a dataset name risks_data - that contains fromdate, todate and risks. fromdate and todate in the format of date9. and risks number. as below.

fromdate todate risks
02MAR2009 02MAR2010 1
21FEB2010 21FEB2011 1
.
.
.

and i am need to find the number of risks in three different months - 1st Jan 2010, 1st Feb 2010, 1st March 2010 so I had the below macro codes.

%macro date;
Data date_&month;
set risks_data ( keep = fromdate todate risks);
Where fromdate <= "%sysfunc(putn(%sysfunc(intnx(Month,%sysfunc(date()),-1)),EURDFDE9.))"D <= todate and risks;
run;
%mend date;

once thats done, I need to tabulate the number of risks into a table showing something as below (this is where I am not sure how to go about doing it)

Effective_Day Risks
01Jan2010 2311
01Feb2010 1452
01March2010 2785


hope someone can help me out on this one!!

thanks in advance!
Yennie
2 REPLIES 2
Yennie
Calcite | Level 5
continue.....
le "%sysfunc(putn(%sysfunc(intnx(Month,%sysfunc(date()),-1)),EURDFDE9.))"D le todate and risks;
run;
%mend date;

once thats done, I need to tabulate the number of risks into a table showing something as below (this is where I am not sure how to go about doing it)

Effective_Day Risks
01Jan2010 2311
01Feb2010 1452
01March2010 2785


hope someone can help me out on this one!!

thanks in advance!
Yennie
Patrick
Opal | Level 21
Hi Yennie

Some questions and ideas.

Q: are the values for fromdate and todate really strings or are these SAS date values with a SAS date format assigned? You can easily check this by running a PROC CONTENTS.

Q: Your example data shows the same dates for fromdate and todate. Is this how your data really looks like? And would that mean that these 2 cases wouldn't be counted anywhere?

Q: What happens if a risk period (fromdate to todate) goes over a monthend. Should this risk be counted in 2 months? Or only when it started?

Forget about using any macro code. It won't be needed.

What most likely has to be done is creating some additional observations (i.e. one obs per month where the risk exists) and then a PROC TABULATE with an appropriate format applied to the variable containing the date.

Have also a look at functions like INTCK() and INTNX().

Please provide also some "real" sample data, best in form of a data step creating a SAS table.

HTH
Patrick Message was edited by: Patrick

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