BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MaryA_Marion
Lapis Lazuli | Level 10

 

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;



 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.

View solution in original post

3 REPLIES 3
Quentin
Super User

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.

MaryA_Marion
Lapis Lazuli | Level 10

Thank you very much. I knew I was close to the correct syntax. MM

 

Reeza
Super User

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;



 

 

 


 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1506 views
  • 3 likes
  • 3 in conversation