BookmarkSubscribeRSS Feed
Bal23
Lapis Lazuli | Level 10
*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

 

3 REPLIES 3
Reeza
Super User

 

 

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;

 

Bal23
Lapis Lazuli | Level 10

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

Reeza
Super User

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. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 934 views
  • 0 likes
  • 2 in conversation