03-11-2016 02:41 PM
*part I. use proc freq to calculate crude relative risk and 95%Ci; data question; input BIG $ Response $ Count; datalines; GR Yes 2256 GR No 212766 SM Yes 10450 SM No 356115 ; %macro rr(PAT); title1 "RR of &PAT"; proc freq data=question order=data ; weight Count; tables BIG*Response / relrisk OUT=RR; run; proc export data = RR outfile = "c:\TABLES" dbms = XLSX replace; sheet = "1.11.&PAT"; run; %mend; %rr(RED);
I want to calculate Relative risks of many groups. This is one of groups. So I use macro.
I want to output the result to a file so that I need NOT to copy and paste the result review of sas each time.
The above code did get relative risk of the group. However, the tables it generates lacks the relative risk that I need
03-11-2016 03:15 PM - edited 03-11-2016 03:15 PM
Your data isn't being stored in your output file so you need to find the ODS table name and store it.
The process is described here. Store the new table name and export the table.
I recommend using Tagsets instead so you don't have to export data.
%macro rr(PAT); title1 "RR of &PAT"; proc freq data=question order=data ; weight Count; tables BIG*Response / relrisk OUT=RR; run; %mend;
ods tagsets.excelxp file='sample.xml' style=meadow;
ods tagsets.excelxp close;
03-11-2016 03:36 PM
my computer cannot access the link you provided.
I used your code, but still I cannot generate a desired file. The file genrated is not a typical excel file. there is no relative risk there
data question; input big $ Response $ Count; datalines; gr Yes 5 gr No 294 sm Yes 18522 sm No 779090 ; %macro rr(ser); title1 "RR of &ser"; proc freq data=question order=data ; weight Count; tables big*Response / relrisk OUT=RR; run; ods tagsets.excelxp file='c:\TABLES11 &ser' style=meadow; run; %mend; %rr(bwlow hs); %mend; ods tagsets.excelxp close;
that I expect
plus, ideally i would like an excel file that I can always add more pages, instead of a single file
03-11-2016 03:52 PM
Tagsets generates an XML file and you can add more sheets.
Each proc outputs a bunch of tables. The tables are documented. Find the name of the table you want and save that using:
ods table relativerisk=rr_out;
Add this Before the proc. I'm not sure what the table name is, you'll have to confirm that. Either reference docs or use ODS TRACE to find the table names.
Export the RR_out file.
As always, get it working outside of the macro first.