BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Woop122
Calcite | Level 5

Hi,

 

I'm trying to get the P-value for a list of 20+ diffent variables to export to excel. I've set it up in a round-about way, but was wondering if there's someway to simplify it to avoid 1000s of lines of code. 

 

Thank you!

 

ODS OUTPUT MODELANOVA=OUTPUT;

PROC LOGISTIC DATA=PAT_LIST_FINAL;
CLASS SEX (REF = "0") ;
MODEL CMV_IND = SEX;
WHERE VLBW_YN = 'VLBW' AND VIRAL_YN = 1;
RUN;

 

PROC PRINT DATA=OUTPUT NOOBS;
RUN;

 

DATA SEX_P_VLBW;
SET OUTPUT;
RUN;

 

ODS OUTPUT MODELANOVA=OUTPUT;

PROC LOGISTIC DATA=PAT_LIST_FINAL;
CLASS LOCATE (REF = "0") ;
MODEL CMV_IND = LOCATE;
WHERE VLBW_YN = 'VLBW' AND VIRAL_YN = 1;
RUN;

 

PROC PRINT DATA=OUTPUT NOOBS;
RUN;

 

DATA LOCATE_P_VLBW;
SET OUTPUT;
RUN;

 

ODS OUTPUT MODELANOVA=OUTPUT;

PROC LOGISTIC DATA=PAT_LIST_FINAL;
CLASS HISP (REF = "0") ;
MODEL CMV_IND = HISP;
WHERE VLBW_YN = 'VLBW' AND VIRAL_YN = 1;
RUN;

 

PROC PRINT DATA=OUTPUT NOOBS;
RUN;

 

DATA HISP_P_VLBW;

SET OUTPUT;
RUN;

 

DATA P_VLBW;
SET
SEX_P_VLBW
LOCATE_P_VLBW
HISP_P_VLBW
;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Rwon
Obsidian | Level 7

Using a macro would shorten the code a bit since the 3 steps prior to the merge are all similar. You can add additional class variables as needed.

 

%macro repeated(class);
ODS OUTPUT MODELANOVA=OUTPUT;
PROC LOGISTIC DATA=PAT_LIST_FINAL;
CLASS &class. (REF = "0") ;
MODEL CMV_IND = &class.;
WHERE VLBW_YN = 'VLBW' AND VIRAL_YN = 1;
RUN;

PROC PRINT DATA=OUTPUT NOOBS;
RUN;
 
DATA &class._P_VLBW;
SET OUTPUT;
RUN;
%mend repeated;

*Similar code for each class variable;
%repeated(class=SEX);
%repeated(class=LOCATE);
%repeated(class=HISP);

DATA P_VLBW;
SET
SEX_P_VLBW
LOCATE_P_VLBW
HISP_P_VLBW
;
RUN;

View solution in original post

1 REPLY 1
Rwon
Obsidian | Level 7

Using a macro would shorten the code a bit since the 3 steps prior to the merge are all similar. You can add additional class variables as needed.

 

%macro repeated(class);
ODS OUTPUT MODELANOVA=OUTPUT;
PROC LOGISTIC DATA=PAT_LIST_FINAL;
CLASS &class. (REF = "0") ;
MODEL CMV_IND = &class.;
WHERE VLBW_YN = 'VLBW' AND VIRAL_YN = 1;
RUN;

PROC PRINT DATA=OUTPUT NOOBS;
RUN;
 
DATA &class._P_VLBW;
SET OUTPUT;
RUN;
%mend repeated;

*Similar code for each class variable;
%repeated(class=SEX);
%repeated(class=LOCATE);
%repeated(class=HISP);

DATA P_VLBW;
SET
SEX_P_VLBW
LOCATE_P_VLBW
HISP_P_VLBW
;
RUN;

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
  • 1 reply
  • 908 views
  • 0 likes
  • 2 in conversation