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;
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
  • 3 replies
  • 1274 views
  • 0 likes
  • 3 in conversation