I am trying to add unique titles to my outputs for proc means and proc univariate results, but the only way I know how to do this is through the insertion of a macro variable which can only be one word. I could use "_" but it needs to be cleaner. Anyone know of a way to create unique titles within a macro process?
What I have so far looks like this:
data have;
set hadbefore;
run;
%let varA=
abc
def
ghi
;
%let varB=
j k l
m n o
p q r
;
%macro test;
%do i=1 %to 3;
ods noproctitle;
%let v = %scan(&varA, &i.);
%let t = %scan(&varB, &i.);
title "&v.";
title2 "&t.";
proc means data=test; (another similar program with proc univariate as well)
var &v;
run;
%end;
%mend test;
%test;
What it does for the title 2 is prints one word for each instead of the whole line. I have tried adding in quotations but then it runs with an error because it picks up the first word with one quotation mark.
Any help would be great thanks.
but the only way I know how to do this is through the insertion of a macro variable which can only be one wordMacro variables can be as many words as you want them to be. So I don't understand this limitation you are stating.
What it does for the title 2 is prints one word for each instead of the whole line.This also makes no sense to me. Can you give us an example of what title you would actually like to see?
Okay, what I meant was what is stored only seems to be taking on one word values. For example, I want two titles in my output. The first title as the variable's name, and the second title as a description of that variable. So for the macro variable varA I store the variable name, and for the macro variable varB I want to store the variable description but I don't know the syntax for creating a macro variable that calls multiple words.
I do not understand why you have all that macro code? Post some have and some want so its easier to see. Anyways, SAS have specific caommands for dealing with this type of thing, its called by var processing. First get your data into a normalised structure, its far easier to work with, and you can use by group processing - note its also CDISC standard.
dataset have looks like:
parameter result idvar
A 5 01
A 6 02
B 3 01
now I can just do:
proc means data=have;
var result;
by parameter;
out=want n=n...;
run;
proc report data=want nowd;
columns ...;
title1 "This is the title for parameter = #byvar(parameter)";
by parameter;
run;
So much simpler, no macro code. Examples:
http://www2.sas.com/proceedings/sugi23/Coders/p75.pdf
Awesome thanks for the help this worked. Totally forgot about adding delimiters should've known from the error messages I was getting.
Use underscore &i, so it will change the name for every iteration.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.