BookmarkSubscribeRSS Feed
enginemane44
Calcite | Level 5
Hello all,
I've been trying to get the following program working without much success. Essentially, I want to run a macro %do loop with a data step WHERE statement to produce a custom report. Here is the code (note the format fxx) :
option symbolgen mprint mlogic;

proc format;

value fxx 1 = 'Cold'
2 = 'Cool'
3 = 'Tepid'
4 = 'Warm'
5 = 'Hot';

option formdlim = ' ';

data one;
input x;
datalines;
1
2
2
3
5
;

%macro runit;
%do i = 1 %to 5;
proc print data = one;
where x = &i;
format x fxx.;
title "Data set ONE from Macro when index is put((&i),fxx.))";
run;
%end;
%mend runit;

%runit

What I want is each where case to procduce the title :
Data set ONE from Macro when index is tepid
Instead SAS either displays the actual character string 'put(3,fxx) 'or says it can't
find the put function.
I can get the macro to run if I use :
title 'Data set ONE with index &i - but then it displays just the number (e.g. 3), not the 'mapped' value (e.g. 'tepid').

I tried %sysfunc, %eval, and even writing a macro to translate the number on the title statement - without success.
Any ideas here ?
Barry Walton
Barry.Walton@millersville.edu
Any ideas here ?
4 REPLIES 4
chang_y_chung_hotmail_com
Obsidian | Level 7
Only if you insist on using macros...
[pre]
proc format;
value temp 1 = "Cold" 2 = "Cool" 3 = "Tepid"
4 = "Warm" 5 = "Hot";
run;

data one;
input x @@;
cards;
1 2 2 3 5
;
run;

%macro printf(x=);
%local xf;
%let xf = %sysfunc(putn(&x, temp.));
title "Data set one from macro where x=&xf";
proc print data=one;
where x = &x;
format x temp.;
run;
title;
%mend printf;

%macro runit();
%local i;
%do i = 1 %to 5;
%printf(x=&i)
%end;
%mend runit;

%runit()
[/pre]
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The OP's SAS program is solid except for the TITLE statement, as shown in post-reply above - the %SYSFUNC(...) needs to be used.

Scott Barry
SBBWorks, Inc.
enginemane44
Calcite | Level 5
All,

The solution given by chang_y_chung worked like the proverbial charm ! The key was declaring xf as a local macro variable and using this statement within a macro to assign the appropriate value :
%let xf = %sysfunc(putn(&x, temp.));
Thanks to all who responded !
Barry Walton
data_null__
Jade | Level 19
Maybe you don't need macros at all.

[pre]
options byline=0;
title "Data set ONE from Macro when index is #byval1";
proc print data = one;
by X;
var x;
format x fxx.;
run;
options byline=1;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 995 views
  • 0 likes
  • 4 in conversation