i have my data like below
Usubjid Avisit
100 WK1
100 WK2
101 WK1
My requirement is to find how many times the subjects appeared in visits , so the needed data should be like below
visit count of subjects in visits
WK1 2
WK2 1
Please do the needful to find this
proc freq data=have;
tables avisit;
run;
I have used below codes and got the counts correctly as i required, but i need to show the corresponding visits also to the data. could you please modify my codes on
proc freq data=mn ;
tables usubjid/out=temp(rename=(count=count1));
run;
proc freq data=temp;
tables count1/out=temp1(keep=count) ;
run;
proc freq data=mn ;
tables usubjid/out=temp(rename=(count=count1));
run;
proc freq data=temp;
tables count1/out=temp1(keep=count) ;
run;
I have used below codes and got the counts correctly as i required, but i need to show the corresponding visits also to the data.
I do not understand what you want. Please explain in more detail, or better yet, show us. Also, you seem to have changed the original question from counting by weeks to counting by USUBJID, please explain that as well.
i have the example data
here we can see the visits number 8 having 2 subjects so the count of subject is 2 here , this is the brief of the data we have
Visits Sub count
5 3 2
6 0
7 1 1
8 5 2
8 5 2
And what should the result from this example data look like, and do you want it as a dataset or a report?
Please answer both parts of my question. Post the expected result from this example data:
Visits Sub count
5 3 2
6 0
7 1 1
8 5 2
8 5 2
I said: "I do not understand what you want. Please explain in more detail, or better yet, show us. Also, you seem to have changed the original question from counting by weeks to counting by USUBJID, please explain that as well."
to which you replied
@ambadi007 wrote:
i have the example data
here we can see the visits number 8 having 2 subjects so the count of subject is 2 here , this is the brief of the data we have
Visits Sub count
5 3 2
6 0
7 1 1
8 5 2
8 5 2
I don't see the connection between this table above and the original one you posted, nor do I understand if this table is the input data or the output data or something else. Please provide clear complete descriptions, emphasis on COMPLETE, emphasis on CLEAR. Please provide both input data and desired output.
If I have correctly understood your question, the following should provide the desired result.
data have;
input Usubjid $ Avisit $;
datalines;
100 WK1
101 WK1
100 WK2
;
run;
proc sql;
/* create table want as */
select
Usubjid
,count(*) as Count label='count of subjects in visits'
from have
group by Usubjid;
quit;
data have;
input Usubjid Avisit $;
cards;
100 WK1
100 WK2
101 WK1
;
proc sql;
create table want as
select avisit,count(distinct usubjid) as count
from have
group by avisit;
quit;
The code you have provided will give number subjects in each visits.. i want how many visits have got each subjects . the below example code will give the desired result, but i am not able to add the corresponding visits in to it, if i add the results are going different , pls see my code
proc freq data=mn ;
tables usubjid/out=temp(rename=(count=count1));
run;
proc freq data=temp;
tables count1/out=temp1(keep=count) ;
run;
See the below requirement , i want the 3rd column , please see the Week5 here 2 subjects achieved response , so the count of subjects will be 2 .. like wise i need to create a dataset
Visits where response achieved | Sub No who achieved response | Count of Subject Number |
week1 | 4 | 1 |
Week2 | 3 | 1 |
week3 | 0 | |
week4 | 1 | 1 |
week5 | 2, 5 | 2 |
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.