Hello,
I am trying to use the PROC REPORT for the first time. I would like to describe the number of people registered for a game in comparison with the number of people interviewed, depending on the country and the week. In fact, I would like to build a table with 3 columns (CF attachment) for each week:
- number of registrants
- number of contacted
- registration rates (number of people registered divided by the number of people interviewed)
Some data:
data test;
input week country $ inscrip;
datalines;
45 france 1
45 france 1
45 france 0
45 espagne 1
45 espagne 0
45 espagne 0
45 espagne 0
45 espagne 0
46 france 1
46 france 1
46 france 1
46 france 0
46 france 0
run;
Here is the code. I can display the columns of people registered and contacted for each week and by country. However, I can't display registration rates for each week.
PROC REPORT data=test nowindows completerows;
columns COUNTRY (WEEK, (INSCRIP n RATE))(INSCRIP n RATE);
define COUNTRY / group ;
define WEEK / across;
define INSCRIP / analysis sum;
define n / "Registrants";
define RATE / computed format=NLPCTN12.2;
compute RATE;
RATE=inscrip.sum/n;
endcomp;
rbreak after / summarize;
RUN;
The error is: "ERROR: COMPUTED conflicts with earlier use of taux". Is there any solution ?
Many thanks in advance.
Garpe
It may help to show the expected results for your given data.
You may consider:
PROC REPORT data=test nowindows completerows; columns COUNTRY WEEK, (INSCRIP,( n mean)); define COUNTRY / group ; define WEEK / across; define INSCRIP / analysis ; define mean/ format=percent8.1 "Rate"; define n / "Adresses"; rbreak after / summarize; RUN;
The Mean of a 0/1 coded variable is the percent of 1 values.
It may help to show the expected results for your given data.
You may consider:
PROC REPORT data=test nowindows completerows; columns COUNTRY WEEK, (INSCRIP,( n mean)); define COUNTRY / group ; define WEEK / across; define INSCRIP / analysis ; define mean/ format=percent8.1 "Rate"; define n / "Adresses"; rbreak after / summarize; RUN;
The Mean of a 0/1 coded variable is the percent of 1 values.
Many thanks (the expected results is on attachment) ! That's exactly what I need. Now the solution seems obvious !
However I have a last question... I have difficulties with the cross and I don't know how to add a column (next to the contacted and the registration rate column) with the registrants by country and week, a suggestion ?
[EDIT]
I don't know if this is the optimal solution but the following code runs
PROC REPORT data=test nowindows completerows; columns COUNTRY WEEK, (INSCRIP INSCRIP,( n mean)); define COUNTRY / group ; define WEEK/ across; define INSCRIP / analysis ; define mean/ format=percent8.1 "Rate"; define n / "Contacted"; rbreak after / summarize; RUN;
Thanks again.
Garpe
If I understand your question here's a hint: The SUM of a 0/1 coded variable is the number of 1's. perhaps you just want to add SUM in an appropriate location.
Yes, I was thinking about adding a SUM but there were errors in my code. I tried again thanks to your post and I finally found a solution:
PROC REPORT data=test nowindows completerows; columns country WEEK, (INSCRIP,(sum n mean)); define COUNTRY / group ; define WEEK / across; define INSCRIP / analysis ; define mean/ format=percent8.1 "Rate"; define n / "Adresses"; rbreak after / summarize; RUN;
Thanks, it will help me a lot!
Garpe
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.