BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacob_klimek
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You use the scan function with no delimiter specified, which means the default delimiter is a SPACE. Add a delimiter to the macro variable and the corresponding delimiter to the SCAN function to separate the macro variables.

%let varB=
j k l|
m n o|
p q r
;
%let i=1;
%let t = %scan(&varB, &i., |);

%put &t;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26
but the only way I know how to do this is through the insertion of a macro variable which can only be one word
Macro 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?
--
Paige Miller
jacob_klimek
Obsidian | Level 7

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

 

Reeza
Super User
You use the scan function with no delimiter specified, which means the default delimiter is a SPACE. Add a delimiter to the macro variable and the corresponding delimiter to the SCAN function to separate the macro variables.

%let varB=
j k l|
m n o|
p q r
;
%let i=1;
%let t = %scan(&varB, &i., |);

%put &t;

jacob_klimek
Obsidian | Level 7

Awesome thanks for the help this worked. Totally forgot about adding delimiters should've known from the error messages I was getting.

Steelers_In_DC
Barite | Level 11

Use underscore &i, so it will change the name for every iteration.

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
  • 6 replies
  • 712 views
  • 0 likes
  • 5 in conversation