BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
_maldini_
Barite | Level 11

Requesting help for syntax that will count the number of respondents in a survey who answered a particular question (SAMPLE DATASET BELOW). The variable type is Check-All-That-Apply (CATA)/Multiple Response Variable. The question asks respondents to identify what type of healthcare provider they are. A respondent could be more than one type of healthcare provider.

 

There are 14 possible responses (i.e. provider_type1-provider_type14). A value of "1" anywhere in provider_type1-provider_type14 would indicate the question has been answered. A value of "0" in provider_type1-provider_type14 would indicate the question has NOT been answered.

 

A respondent could be an MD and an RN, for example, in which case a value of "1 would be registered for provider_type1 and provider_type6 respectively.

VAR record_id provider_type___1-provider_type___14;

LABEL
provider_type___1 = "Medical Doctor (i.e. MD)"
provider_type___2 = "Osteopathic Doctor (i.e. DO)"
provider_type___3 = "Naturopathic Doctor (i.e. ND)"
provider_type___4 = "Physicians Assistant (i.e. PA)"
provider_type___5 = "Nurse Practitioner (i.e. NP)"
provider_type___6 = "Registered Nurse (i.e. RN)"
provider_type___7 = "Pharmacist (i.e. Rph)"
provider_type___8 = "Massage therapist (i.e. LMP)"
provider_type___9 = "Acupuncturist (i.e. LAc)"
provider_type___10 = "Chiropractor (i.e. DC)"
provider_type___11 = "Clinical social worker (i.e. LCSW)"
provider_type___12 = "Physical therapist (i.e. PT)"
provider_type___13 = "Psychiatrist"
provider_type___14 = "Other";
    
TITLE "What type of licensed healthcare provider are you?";

 

 

data WORK.SAS_COMMUNITIES;
infile datalines;
input record_id provider_type___1-provider_type___14;
datalines;
1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 1 0 0 0 0 0 0 0 0 0 0 0 0 0
4 1 0 0 0 0 0 0 0 0 0 0 0 0 0
5 1 0 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 1 0 0 0 0 0 0 0 0
7 0 0 0 0 0 1 0 0 0 0 0 0 0 0
8 0 0 0 0 0 1 0 0 0 0 0 0 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0 0 0 0 1 0 0 0 0 0 0 0 0
95 0 0 0 0 0 1 0 0 0 0 0 0 0 0
96 0 0 0 0 0 1 0 0 0 0 0 0 0 0
97 0 0 0 0 0 1 0 0 0 0 0 0 0 0
98 0 0 0 0 0 1 0 0 0 0 0 0 0 0
99 0 0 0 0 1 0 0 0 0 0 0 0 0 0
 ;;;;

Thanks for your help!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@_maldini_ wrote:

@ballardw This is great. Thank you so much.

 

<I don't think you have stated what you want for percentage in the "total" of the last table.>

 

That's correct. I didn't. I don't think it makes sense because it sums to over 100%. You could manually assign a value such as 100 in the data step that creates the "Total" label OR the value of your wanted denominator / actual total respondents but that would likely require an explanation

 

For some reason, when I adapt your syntax to the overall dataset, there is a problem w/ the array (see syntax below): "All variables in array list must be the same type, i.e., all numeric or character."

 

A PROC CONTENTS shows that all the variables in the array ARE the same type - numeric. I don't understand arrays very well. Can you tell what I'm doing wrong?

 


If you have another variable in the actual data set that starts with Provider_ then the short cut will try to include that. Remember that your KEEP statement sets which variables go to the OUTPUT data set. All the other variables are on the data vector.

Likely the fix would be to explicitly list the variable range.

array p provider_type___1 - provider_type___14 ;

I don't allow my programs to create variables with multiple _ characters and was just avoiding typing them.

View solution in original post

17 REPLIES 17
PaigeMiller
Diamond | Level 26
data WORK.SAS_COMMUNITIES;
    infile datalines;
    input record_id provider_type1-provider_type14;
    answered=sum(of provider_type1-provider_type14);
    datalines;
...
;
run;

 

--
Paige Miller
_maldini_
Barite | Level 11

@PaigeMiller  Thanks for your assistance, but I can't get this syntax to run.

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data WORK.SAS_COMMUNITIES;
74 infile datalines;
75 input record_id provider_type1-provider_type14;
76 answered=sum(of provider_type1-provider_type14);
77 datalines;
 
NOTE: Invalid data for record_id in line 78 1-3.
NOTE: LOST CARD.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
79 ;
NOTE: Invalid data errors for file CARDS occurred outside the printed range.
NOTE: Increase available buffer lines with the INFILE n= option.
record_id=. provider_type1=. provider_type2=. provider_type3=. provider_type4=. provider_type5=. provider_type6=. provider_type7=.
provider_type8=. provider_type9=. provider_type10=. provider_type11=. provider_type12=. provider_type13=. provider_type14=.
answered=. _ERROR_=1 _N_=1
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.SAS_COMMUNITIES has 0 observations and 16 variables.
Reeza
Super User

You put in the datalines he deleted?

 

 data temp;
 set sas_communities;
 denom = sum(of provider_type1-provider_type14) >0;
 if sum(of provider_type1-provider_type14) = 0 then call missing(of provider_type1-provider_type14);
 ;
 run;


 ods select none;
proc means data=temp stackods N sum mean maxdec=4;
var provider_type: denom;
ods output summary = want;
run;
ods select all;

proc print data=want;run;

Your data structure is problematic because you're essentially using 0 as both No and Missing. 

So I changed the values to missing if it was actually missing, or all 0's.

 

Then I did the PROC MEANS to get the correct results desired. You can check the math by dividing the SUM by the DENOM sum, so you have 73 respondents in the data you posted. 

Reeza
Super User

Is this what you're looking for:

 

 ods select none;
proc means data=sas_communities stackods N sum maxdec=0;
var provider_type:;
ods output summary = want;
run;
ods select all;

proc print data=want;run;

 

 

_maldini_
Barite | Level 11

This is helpful, but the "n"= 82, which is the total number of observations in the dataset (record_id goes up to 99), as opposed to the total number of respondents who answered the question. 

 

For example, for record_id = 85, provider_type___1 to provider_type___14 contains "0". This respondent did not answer this question and should not be included in the "n".

 

 

ballardw
Super User

I believe we have seen some of this question at least 3 times now. We have asked for an example of output given an example input statement and a description of logic where your "n" is different than the actual data shows. I don't believe we have gotten an example with input  and output that match.

 

We are guessing because you are not providing sufficient details to determine your logic. You say something like 'not what I want' but not how to actually get what you want.

 

Pick a small enough example of data that you can manually calculate what you want. Include cases that demonstrate all the behaviors that need to be considered. Then show us the desired output for that smaller example input.

 

It may not hurt to describe what you need to do when "n" matches your expectations as well.

 

Why did you pick record_id=85 when 2 or 17 or 18 or 23  has the same behavior?

_maldini_
Barite | Level 11

@ballardw I will attempt to explain again. 

 

The dataset above - WORK.SAS_COMMUNITIES - has 82 observations. This is a subset of the overall dataset. That number - 82 - is being used as the "n" and as the denominator for calculating Percent (of Respondents) in the last column of the attached PROC TABULATE output/table (See below). I want the "n" and the denominator to be the number of respondents who have answered the question, not the number of observations in the dataset. 

 

You are correct, record_id=2, 17, 18, 23, 38, 41, 61, 85, and 86 exhibit "the same behavior" (i.e. A value of "0" in provider_type1-provider_type14 when the question has NOT been answered.). 82 - 9  = 73. I don't know how to calculate this in SAS, so I am doing it manually. I hope I identified the correct number, 9.

 

73 out of 82 respondents answered this question, according to the WORK.SAS_COMMUNITIES dataset. Therefore, 73, in this example, is the "n" and the denominator I am seeking. 

 

This is the syntax I am using:

PROC TABULATE DATA=WORK.SAS_COMMUNITIES ORDER=formatted; 
	VAR provider_type___1-provider_type___14 record_id;
	
	TABLE provider_type___1 - provider_type___14 ,
			(n='n'*f=7. Sum='Count'*f=7. mean='Percent'*f=percent8.1);
   LABEL
	provider_type___1	= "Medical Doctor (i.e. MD)"
	provider_type___2   = "Osteopathic Doctor (i.e. DO)"
	provider_type___3 	= "Naturopathic Doctor (i.e. ND)"
	provider_type___4	= "Physicians Assistant (i.e. PA)"
	provider_type___5	= "Nurse Practitioner (i.e. NP)"
	provider_type___6	= "Registered Nurse (i.e. RN)"
	provider_type___7	= "Pharmacist (i.e. Rph)"
	provider_type___8	= "Massage therapist (i.e. LMP)"
	provider_type___9   = "Acupuncturist (i.e. LAc)"
	provider_type___10	= "Chiropractor (i.e. DC)"
	provider_type___11   = "Clinical social worker (i.e. LCSW)"
	provider_type___12 	= "Physical therapist (i.e. PT)"
	provider_type___13	= "Psychiatrist"
	provider_type___14	= "Other";
    
    TITLE "What type of licensed healthcare provider are you?";
RUN;

*-----------------------------------------------;
* PROVIDER TYPE - LICENSED - SORTED;
*-----------------------------------------------;

DATA data_working_keep;
	KEEP record_id provider_type___1-provider_type___14;
	SET WORK.SAS_COMMUNITIES;
	
	LABEL 
	provider_type___1	= "Medical Doctor (i.e. MD)"
   	provider_type___2   = "Osteopathic Doctor (i.e. DO)"
   	provider_type___3 	= "Naturopathic Doctor (i.e. ND)"
	provider_type___4	= "Physicians Assistant (i.e. PA)"
	provider_type___5	= "Nurse Practitioner (i.e. NP)"
	provider_type___6	= "Registered Nurse (i.e. RN)"
	provider_type___7	= "Pharmacist (i.e. Rph)"
	provider_type___8	= "Massage therapist (i.e. LMP)"
	provider_type___9   = "Acupuncturist (i.e. LAc)"
	provider_type___10	= "Chiropractor (i.e. DC)"
	provider_type___11   = "Clinical social worker (i.e. LCSW)"
	provider_type___12 	= "Physical therapist (i.e. PT)"
	provider_type___13	= "Psychiatrist"
	provider_type___14	= "Other";	
RUN;

proc sort data=data_working_keep;
   by  record_id;
run;

Proc transpose data=data_working_keep
   out=trans_mchps;
	by record_id;
run;

*proc tabulate data=trans_mchps;
  *where col1=1;
  *class _label_ /order=freq;
  *label _label_='Response';
  *table _label_ all='Total',
        n='n'*f=best6. colpctn='%'
      /
   ;
*run;

proc summary data=trans_mchps;
   class _label_;
   var col1;
   output out=transsum n= sum=/autoname;
run;

proc sort data=transsum;
   by descending _type_ descending col1_sum ;
run;

data display;
  set transsum;
  if missing(_label_) then do;
      _label_ ='Total';
      percent= 999;
  end;
  else percent = 10.*(col1_sum/col1_n);
run;

proc print data=display noobs label;
   var _label_;
   var col1_sum / style(data)={just=c};
   var percent / style(data)={just=c}; 
   label _label_='Response'
         col1_sum='Number selected'
         percent='Percent of Respondents'
   ;
   format col1_sum best6. percent f5.1;
   
   TITLE "What type of licensed healthcare provider are you?";
   TITLE2 "NOTE: This is a multiple response variable (i.e. Check all that apply) so the column does not sum to 100%";
   TITLE3 "Percent of RESPONDENTS, not responses ";
   TITLE4 "n = TBD";
run;

 

The "n" in the first table (Unsorted) is 82. I would like it to be 73. Same for the second table (Sorted).

licensed providers 4.jpg

I understand if you are frustrated. Please know that you are no more frustrated than I. Trying to decipher suggested syntax and interpret the SAS vernacular used in many of the responses to my posts are both very challenging. I am not a SAS expert.

 

Thanks for your time and assistance. 

 

Reeza
Super User

Did you try my solution? The mean are the percents, isn’t that what you wanted?

_maldini_
Barite | Level 11

@Reeza Yes, this is what I was asking for in this thread. Thank you! 

 

In another thread I had been seeking a more comprehensive solution using PROC TABULATE. This is what @ballardw was referring to.

 

Thank you for your help.

ballardw
Super User

Another stab

data WORK.SAS_COMMUNITIES;
   infile datalines;
   input record_id provider_type___1-provider_type___14;
   array p provider_: ;
   if sum(of p(*))=0 then call missing(of p(*));
   LABEL
	provider_type___1	= "Medical Doctor (i.e. MD)"
	provider_type___2   = "Osteopathic Doctor (i.e. DO)"
	provider_type___3 	= "Naturopathic Doctor (i.e. ND)"
	provider_type___4	= "Physicians Assistant (i.e. PA)"
	provider_type___5	= "Nurse Practitioner (i.e. NP)"
	provider_type___6	= "Registered Nurse (i.e. RN)"
	provider_type___7	= "Pharmacist (i.e. Rph)"
	provider_type___8	= "Massage therapist (i.e. LMP)"
	provider_type___9   = "Acupuncturist (i.e. LAc)"
	provider_type___10	= "Chiropractor (i.e. DC)"
	provider_type___11   = "Clinical social worker (i.e. LCSW)"
	provider_type___12 	= "Physical therapist (i.e. PT)"
	provider_type___13	= "Psychiatrist"
	provider_type___14	= "Other"
   ;
datalines;
1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 1 0 0 0 0 0 0 0 0 0 0 0 0 0
4 1 0 0 0 0 0 0 0 0 0 0 0 0 0
5 1 0 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 1 0 0 0 0 0 0 0 0
7 0 0 0 0 0 1 0 0 0 0 0 0 0 0
8 0 0 0 0 0 1 0 0 0 0 0 0 0 0
13 1 0 0 0 0 0 0 0 0 0 0 0 0 0
16 0 0 0 0 0 0 0 0 0 0 0 0 0 1
17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
18 0 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1 0 0 0 0 0 0 0 0
98 0 0 0 0 0 1 0 0 0 0 0 0 0 0
99 0 0 0 0 1 0 0 0 0 0 0 0 0 0
 ;;;;

 PROC TABULATE DATA=WORK.SAS_COMMUNITIES ORDER=formatted ; 
	VAR provider_type___1-provider_type___14 record_id;
	
	TABLE provider_type___1 - provider_type___14 ,
			(n='n'*f=7. Sum='Count'*f=7. mean='Percent'*f=percent8.1);
run;
Proc transpose data=WORK.SAS_COMMUNITIES
  label=_label_ out=work.trans_mchps ;
	by record_id;
run;
proc summary data=work.trans_mchps ;
   class _label_;
   var col1;
   output out=work.summary  sum= n= /autoname;
run;

proc sort data=work.summary;
  by descending _type_ descending col1_sum;
run;

data work.print;
   set work.summary;
   if _type_=0 then do;
      _label_='Total';
      pct=.;/* this remains problematic*/
   end;
   else  pct = 100*col1_sum/col1_n;
   label
      _label_ = "Response"
      col1_sum= "Number Selected"
      pct     = "Percent of Respondents"
   ;
run;

proc print data=work.print noobs label;
   var _label_ col1_sum pct;
   format pct f5.1;
run;
   


I don't think you have stated what you want for percentage in the "total" of the last table. I'm not sure 100 is appropriate. The _freq_ variable in the work.summary set used in work.print could be captured to use the 82 of raw respondents to get a 77/82 as a percentage of respondents with at least one selection if that is the desired percentage.

_maldini_
Barite | Level 11

@ballardw This is great. Thank you so much.

 

<I don't think you have stated what you want for percentage in the "total" of the last table.>

 

That's correct. I didn't. I don't think it makes sense because it sums to over 100%. 

 

For some reason, when I adapt your syntax to the overall dataset, there is a problem w/ the array (see syntax below): "All variables in array list must be the same type, i.e., all numeric or character."

 

A PROC CONTENTS shows that all the variables in the array ARE the same type - numeric. I don't understand arrays very well. Can you tell what I'm doing wrong?

 

DATA data_working_keep;
	KEEP record_id provider_type___1-provider_type___14;
	SET mchps.data_working;
	
	array p provider_: ;
   	if sum(of p(*))=0 then call missing(of p(*));
   
	LABEL 
	provider_type___1	= "Medical Doctor (i.e. MD)"
   	provider_type___2   = "Osteopathic Doctor (i.e. DO)"
   	provider_type___3 	= "Naturopathic Doctor (i.e. ND)"
	provider_type___4	= "Physicians Assistant (i.e. PA)"
	provider_type___5	= "Nurse Practitioner (i.e. NP)"
	provider_type___6	= "Registered Nurse (i.e. RN)"
	provider_type___7	= "Pharmacist (i.e. Rph)"
	provider_type___8	= "Massage therapist (i.e. LMP)"
	provider_type___9   = "Acupuncturist (i.e. LA.c)"
	provider_type___10	 = "Chiropractor (i.e. DC)"
	provider_type___11 = "Clinical social worker (i.e. LCSW)"
	provider_type___12 = "Physical therapist (i.e. PT)"
	provider_type___13	= "Psychiatrist"
	provider_type___14	= "Other";	
RUN;
Reeza
Super User
recordID is listed in the VAR statement as well. Is that numeric or character?
Reeza
Super User
The SAS log is rarely wrong. I suggest posting the full code/log. The log usually indicates where to check, ie which line and which variable.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 17 replies
  • 3277 views
  • 11 likes
  • 5 in conversation