I want to print pairs of variables (24 pair of form temp&i tempc&i) using an inline macro. See code below. How to do?
Also, my numeric day variable will not output using put statement?
Thank you.
MM
GOAL:
data _null_; set FtoC4;
file print;
put Day Date temp1 tempc1 temp2 tempc2 ... temp24 tempc24;
run;
and
proc print data=FtoC4;
var Day Date temp1 tempc1 temp2 tempc2 ... temp24 tempc24;
run;
Attempts:
proc print data=FtoC4;
var Day Date (temp1 temp1c) - (temp24 tempc24);
title 'q1f';
run;
options mrecall;
%macro readin;
%do i=1 %to 24;
temp&i tempc&i;
%end;
%mend;
%readin;
proc print data=FtoC4;
var Day Date %readin;
title 'q1f';
run;
data _null_; set FtoC4;
format day 8.0 date mmddyy10.;
file print;
put day date;
run;
You don't want the semicolon in:
%macro readin;
%do i=1 %to 24;
temp&i tempc&i; /*this semicolon is bad*/
%end;
%mend;
%readin;
Because it means:
proc print data=FtoC4;
var Day Date %readin;
title 'q1f';
run;
Will generate VAR statement:
var Day Date temp1 tempc1; temp2 tempc2; ... temp24 tempc24;;
If you remove the semicolon, it should work.
You don't want the semicolon in:
%macro readin;
%do i=1 %to 24;
temp&i tempc&i; /*this semicolon is bad*/
%end;
%mend;
%readin;
Because it means:
proc print data=FtoC4;
var Day Date %readin;
title 'q1f';
run;
Will generate VAR statement:
var Day Date temp1 tempc1; temp2 tempc2; ... temp24 tempc24;;
If you remove the semicolon, it should work.
Thank you very much. I knew I was close to the correct syntax. MM
Not an answer to your question, but some alternatives that could be helpful.
proc print data=FtoC4;
var Day Date %readin;
title 'q1f';
run;
Is equivalent to:
pproc print data=FtoC4;
var Day Date temp1-temp24 tempc1-tempc24;
title 'q1f';
run;
If you have no other variables with the prefix temp, this would also work, so it's worth taking some time to consider your naming conventions. This would include variables such as temp_id, tempb1 etc so it can be dangerous to use this one.
proc print data=FtoC4;
var Day Date temp: ;
title 'q1f';
run;
Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
@MaryA_Marion wrote:
I want to print pairs of variables (24 pair of form temp&i tempc&i) using an inline macro. See code below. How to do?
Also, my numeric day variable will not output using put statement?
Thank you.
MM
GOAL:
data _null_; set FtoC4;
file print;
put Day Date temp1 tempc1 temp2 tempc2 ... temp24 tempc24;
run;
and
proc print data=FtoC4;
var Day Date temp1 tempc1 temp2 tempc2 ... temp24 tempc24;
run;
Attempts:
proc print data=FtoC4;
var Day Date (temp1 temp1c) - (temp24 tempc24);
title 'q1f';
run;
options mrecall;
%macro readin;
%do i=1 %to 24;
temp&i tempc&i;
%end;
%mend;
%readin;
proc print data=FtoC4;
var Day Date %readin;
title 'q1f';
run;
data _null_; set FtoC4;
format day 8.0 date mmddyy10.;
file print;
put day date;
run;
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!
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.