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.

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.

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.

BASUG is hosting free webinars ! Check out recordings of our past webinars: https://www.basug.org/videos. Save the date for our in person SAS Blowout on Oct 18 in Cambridge, MA. Registration opens in September.
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;



 

 

 


 

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1002 views
  • 3 likes
  • 3 in conversation