DATA Step, Macro, Functions and more

why my output file does not inlcude relative risk

Reply
Super Contributor
Posts: 345

why my output file does not inlcude relative risk

*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

 

Super User
Posts: 19,862

Re: why my output file does not inlcude relative risk

[ Edited ]

 

 

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.

https://statgeeks.wordpress.com/2013/08/11/how-do-i-get-my-sas-results-into-a-data-set/

 

 

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;
%rr(Pat);
%rr(Sec);
%rr(Third);
ods tagsets.excelxp close;

 

Super Contributor
Posts: 345

Re: why my output file does not inlcude relative risk

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

Super User
Posts: 19,862

Re: why my output file does not inlcude relative risk

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. 

Ask a Question
Discussion stats
  • 3 replies
  • 226 views
  • 0 likes
  • 2 in conversation