BookmarkSubscribeRSS Feed
patrick5
Calcite | Level 5

I have a dataset with 28 analytes (e.g., glucose, creatinine, calcium) that I want to run through the same procedure.  To do so, I renamed all 29 analytes as x1 through x28 (to avoid having to make 28 calls to the macro), created a macro, and generated labels in a prior data step to keep track of what each one represented.  However, when running the macro, the labels are not attached, so the results are not quickly identifiable as pertaining to a given analyte.  I would like to be able to look at the results and know that this one is for glucose, this one for creatinine, etc.  How can I get the label/actual analyte name to display in the title?  I tried including "OPTION LABEL" in the macro to no avail.

%MACRO linear_trend;
	%DO i=1 %TO 28;
	PROC MIXED DATA = analytes;
		CLASS patient_id week;
		MODEL x&i = date / SOLUTION;
		RANDOM INT / SUBJECT = patient_id;
		RANDOM INT / SUBJECT = week(patient_id);
                TITLE1 "Linear trend for x&i";
	RUN;
	%END;
%MEND linear_trend;

The data have the form:

patient_id  week  x1    x2    x3 .... x28

123             1      9.1  3.6   7.2 .....

123             1      9.2  3.6   7.4 .....

123             2      8.7  3.7   7.5 .....

.....

2 REPLIES 2
Reeza
Super User

What happens if you run the following:

 

	PROC MIXED DATA = analytes;
		CLASS patient_id week;
		MODEL x1-x28 = date / SOLUTION;
		RANDOM INT / SUBJECT = patient_id;
		RANDOM INT / SUBJECT = week(patient_id);
	RUN;
Reeza
Super User

Other options, I would recommend transposing your data and then running regression using the BY statement instead. This is illustrated in this blog post:

 

https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html

 

Transposing data tutorials:
Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/

A simple reformatting of your data will make your life infinitely easier, your code will be dynamic and adjust to an increase/decrease automatically and the results are easier to collate into a single data set, when you get to that point.

 


@patrick5 wrote:

I have a dataset with 28 analytes (e.g., glucose, creatinine, calcium) that I want to run through the same procedure.  To do so, I renamed all 29 analytes as x1 through x28 (to avoid having to make 28 calls to the macro), created a macro, and generated labels in a prior data step to keep track of what each one represented.  However, when running the macro, the labels are not attached, so the results are not quickly identifiable as pertaining to a given analyte.  I would like to be able to look at the results and know that this one is for glucose, this one for creatinine, etc.  How can I get the label/actual analyte name to display in the title?  I tried including "OPTION LABEL" in the macro to no avail.

%MACRO linear_trend;
	%DO i=1 %TO 28;
	PROC MIXED DATA = analytes;
		CLASS patient_id week;
		MODEL x&i = date / SOLUTION;
		RANDOM INT / SUBJECT = patient_id;
		RANDOM INT / SUBJECT = week(patient_id);
                TITLE1 "Linear trend for x&i";
	RUN;
	%END;
%MEND linear_trend;

The data have the form:

patient_id  week  x1    x2    x3 .... x28

123             1      9.1  3.6   7.2 .....

123             1      9.2  3.6   7.4 .....

123             2      8.7  3.7   7.5 .....

.....


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 435 views
  • 0 likes
  • 2 in conversation