Hi,
I have a dataset that look like the following:
pt_id var. var. var. date_examination date_group
1. 01.01.90 1
1 02.01.90 1
1 03.01.90 2
2 01.01.90 1
3 03.01.90 4
3 10.01.90 3
I want to count how many patients have examination dates in the specific date_groups but only appear 1 time in the output. Some patients have several examinations in the same date_group.
Any ideas?
Thanks 🙂
You might end up having to provide a bit longer example. If variables do not have any affect on the output please do not bother to include them in example data.
So do your 3 "var." variables have any role? or the date_examination? If so describe what that might be.
I can interpret your description more than one way so you may end up having to provide which desired output.
One way is to count the combinations of pt_id and date_group and then count the pt_id in that result. The second result gives how many times pt_id appeared with different date group(s) but not which ones.
Proc freq data=have noprint; tables pt_id*date_group/list out=count1 nocum; run; proc freq data=count1; tables pt_id; run;
It is best to provide example data in the form of a data step so we can recreate your data. Post the code in a code box opened on the forum with the </> icon as I have to prevent the message window from reformatting the text so that the code will not run.
@lone0708 wrote:
Hi Ballardw,
thanks for your reply, I am sorry for the poor question.
The 3 "var" has no role. The date_examination was to illustrate, that dates can vary, but the date_group does not necessarily change because of that.
I can't provide example data, as I am not allowed to.
Your code works, but is it possible to see/add which date_groups the pt_id appears in?
The count1 data set will have one record per Id date_group. You could print that.
Or either of these for different display than proc print:
proc tabulate data=count1; class pt_id date_group; table pt_id='', date_group*n='' /misstext=' ' box=pt_id ; run; proc report data=count1; columns pt_id date_group ; define pt_id /group; define date_group/ across; run;
These two tables will have a 1 indicating that the pt_id appeared with that date_group
Or you could use the original data set with either of these to create a matrix with the cells having the count of times the date_group appeared with the Pt_id.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.