BookmarkSubscribeRSS Feed
jusjolly
Calcite | Level 5

Hi folks,

 

The data looks like this

caseID          servicedate              indicator           sBP

10000           2020-01-10              1                       110

10000           2020-01-11              0                       99

10000           2020-03-10              1                       101

10000           2020-04-11              0                       124

10001           2020-01-11              1                       127

10001           2020-02-20              1                       98

10001           2020-03-15              0                       88

10001           2020-03-29              1                       109

 

I am trying to tabulate

(1) the number of unique case IDs which had a sBP measurement per month (it does not matter what the sBP measurement was, just that it occurred) where the indicator variable equals 1. In the above example, I would want to count row 1, 3, 5, 6 and 8.

 

As well as

(2) the total number of sBP measurements overall per month (again the value of the measurement is not important). Here, we would like to count all rows.

 

The date format is yymmdn6. I was hoping to somehow specify the month in the servicedate  

 

 

 

3 REPLIES 3
japelin
Rhodochrosite | Level 12

how about this?

I'm using the monyy5. format to create the year and month values.

data have;
  length  caseid servicedate indicator sBP ymc $5.;
  input caseid servicedate:yymmdd10. indicator sBP;
  format servicedate yymmdd10. ;
  ymc=put(servicedate,monyy5.);
datalines;
10000           2020-01-10              1                       110
10000           2020-01-11              0                       99
10000           2020-03-10              1                       101
10000           2020-04-11              0                       124
10001           2020-01-11              1                       127
10001           2020-02-20              1                       98
10001           2020-03-15              0                       88
10001           2020-03-29              1                       109
;
run;

proc sort data=have out=want1 nodupkey;
  by caseid ymn;
  where indicator=1;
run;
proc tabulate data=want1 out=out1;
  var caseid;
  table all;
  where indicator=1;
run;

proc tabulate data=have out=out2;
  class ymc;
  table ymc;
run;
PeterClemmensen
Tourmaline | Level 20

@japelin, you have ymc in your test data and ymn in your first proc sort 🙂

PeterClemmensen
Tourmaline | Level 20

@jusjolly, this type of question is easier to solve if you post your desired result. 

 

Anyways, I think this is what you want

 

data have;
input caseid servicedate:yymmdd10. indicator sBP;
format servicedate yymmdd10.;
ymn=put(servicedate,monyy5.);
datalines;
10000 2020-01-10 1 110 
10000 2020-01-11 0 99  
10000 2020-03-10 1 101 
10000 2020-04-11 0 124 
10001 2020-01-11 1 127 
10001 2020-02-20 1 98  
10001 2020-03-15 0 88  
10001 2020-03-29 1 109 
;

proc sql;
   select caseID
        , put(servicedate,monyy5.) as month
		, count(*) as count
   from have
   where indicator = 1
   group by caseID, calculated month;

   select caseid
         ,put(servicedate,monyy5.) as month
         ,count(sBP) as count
   from have
   group by caseID, calculated month;
quit;

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
  • 3 replies
  • 380 views
  • 0 likes
  • 3 in conversation