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

Hello SAS community,

when I run 

proc freq data=have;

tables month * Q1 * Q2 / list nocum;

run;

I get the following (showing partial output)

 

month

Q1

Q2

Frequency

Percent

Feb-20

1

1

92

17.29

Mar-20

1

1

41

7.71

Sep-20

1

0

9

1.69

Sep-20

1

1

34

6.39

Oct-20

1

0

15

2.82

Oct-20

1

1

39

7.33

Nov-20

1

0

25

4.7

Nov-20

1

1

20

3.76

 

I would like to get the count and % (no decimal places) of subjects who answered one or both questions each month, e.g. in Nov, out of a total of 45 subjects, 44% answered both and 56% answered Q1 only.

Should I use proc report and if so how?

I'm running SAS 9.4 on Windows.

 

Any help would be appreciated!

Margaret

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

Sounds like you might want ROWPCTN in Proc TABULATE.

 

Example:

data have;
  call streaminit(2020);
  do date = '01jan2020'd to '31dec2020'd;
    do rep = 1 to rand('integer',2,5);
      Q1 = rand('uniform') < 0.6;
      Q2 = rand('uniform') < 0.4;
      output;
    end;
  end;
run;

proc tabulate data=have;
  class date q1 q2;
  format date monyy6.;
  
  table 
    date
  , 
    q1='Q1 * Q2'*q2=''*n=''
    q1='Q1 * Q2'*q2='' * rowpctn * f=3.
  ;
run;

Produces 

RichardADeVenezia_0-1607922477219.png

 

View solution in original post

3 REPLIES 3
RichardDeVen
Barite | Level 11

Sounds like you might want ROWPCTN in Proc TABULATE.

 

Example:

data have;
  call streaminit(2020);
  do date = '01jan2020'd to '31dec2020'd;
    do rep = 1 to rand('integer',2,5);
      Q1 = rand('uniform') < 0.6;
      Q2 = rand('uniform') < 0.4;
      output;
    end;
  end;
run;

proc tabulate data=have;
  class date q1 q2;
  format date monyy6.;
  
  table 
    date
  , 
    q1='Q1 * Q2'*q2=''*n=''
    q1='Q1 * Q2'*q2='' * rowpctn * f=3.
  ;
run;

Produces 

RichardADeVenezia_0-1607922477219.png

 

urban58
Quartz | Level 8
Thank you, that worked great!
Ksharp
Super User

Here is an example .

 

proc sql;
create table want as
select sex,age,
count(*)/(select count(*) from sashelp.class where sex=a.sex) as per format=percent8.2
 from sashelp.class as a
  group by sex,age;
quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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