BookmarkSubscribeRSS Feed
ambadi007
Quartz | Level 8

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 

17 REPLIES 17
PaigeMiller
Diamond | Level 26
proc freq data=have;
    tables avisit;
run;
--
Paige Miller
ambadi007
Quartz | Level 8

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; 

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ambadi007
Quartz | Level 8

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

ambadi007
Quartz | Level 8
I want it as a dataset
Kurt_Bremser
Super User

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

PaigeMiller
Diamond | Level 26

@ambadi007 

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.

--
Paige Miller
Patrick
Opal | Level 21

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;

 Patrick_0-1735258429289.png

 

ambadi007
Quartz | Level 8
This count is correct , but I want to show the visit column also in the dataset.. that is my exact requirement

Ksharp
Super User
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;
ambadi007
Quartz | Level 8

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; 
Ksharp
Super User
I am unable to understand your question.
Better post some MORE data and DESIRED output to clarify your problem.
ambadi007
Quartz | Level 8

 

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
week141
Week231
week3 0
week411
week52, 52
   

SAS Innovate 2025: Register Today!

 

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 1096 views
  • 0 likes
  • 6 in conversation