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

Hello

I have a parameter that get values : a,b,c,d,e

I have proc print that run on tables:  tbl_a  ,   tbl_b   ,tbl_c,   tbl_d,   tbl_e

And in each report there is a title statement  (Title "&Param.")

My request :

 

Each time that value "a"  is on title of proc print I want to write "Group1".

Each time that value "b"  is on title of proc print I want to write "Group2".

Each time that value "c"  is on title of proc print I want to write "Group3".

Each time that value "d"  is on title of proc print I want to write "Group4".

Each time that value "e"  is on title of proc print I want to write "Group5".

How can I do it please

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Given this structure to the program, I would replace the existing TITLE statement with:

 

Title

%if &param=a %then '0-20';

%else %if &param=b %then '20-40';

%else %if &param=c %then '40+';

;

 

For a limited number of values, %IF/THEN handles it well.

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

It sure feels like you left something out of the explanation here.

 

Do you mean this:

 

A macro that knows a is the first letter of the alphabet and so it replaces a with group1

and it knows that b is the second letter of the alphabet and so it replaces b with group2

and it knows that m is the 13th letter of the alphabet and so it replaces m with group13

 

Or do you mean something else? (please explain in a lot more detail)

--
Paige Miller
Shmuel
Garnet | Level 18

The most simple way is to assign 2 macro variables

    when mac1 = a then mac2 = Group2

etc.

Astounding
PROC Star

Luckily, this is easy.

 

Unluckily, the best way to do it depends highly on what you have coded so far.

 

Show what your macro code (and macro calls) look like without a TITLE statement.  If you have an otherwise-working macro, inserting the TITLE statement will be easy.  But if your macro code doesn't work, even without a TITLE statement, you have to fix that first.

Ronein
Meteorite | Level 14

I am at home so dont have SAS but i will write an example to simple code and what I need.

In the code you can see a statement  Title “&param1.”;

I want that instead of written ’a’  to be written '0-20'

I want that instead of written ’b’  to be written '20-40'

I want that instead of written b’  to be written '40+'

 

data tbl;

input  x  y;

cards;

1  10

2  15

3  30

4  40

5  50

;

Run;

 

Data tbl2;

Set tbl1;

IF y<=20 then Ind=’a’;

Else If y>20 and y<=40 then Ind=’b’;

Else If y>40 then Ind=’c’;

Run;

 

 

%let vector=a+b+c;

%macro test;

%do i=1 %to 3;

%let param1 = %scan(&vector,i,+);

PROC SQL;

Create table  Summarry_&param1.  AS

SELECT  count(*)  as NoObs

FROM tbl2

 WHERE  Ind=&param1.

QUIT;

Title “&param1.”;

Proc print data= Summarry_&param1.    Noobs;

Run;

%end;

%mend test;

Reeza
Super User
You can set up an account under SAS Academics on Demand (Independent Learner) to get access to a cloud version of SAS.
Astounding
PROC Star

Given this structure to the program, I would replace the existing TITLE statement with:

 

Title

%if &param=a %then '0-20';

%else %if &param=b %then '20-40';

%else %if &param=c %then '40+';

;

 

For a limited number of values, %IF/THEN handles it well.

PaigeMiller
Diamond | Level 26

I agree with @Astounding.

 

This is very easy to do, as he has shown.

 

What I don't understand about the original question, which you @Ronein really haven't explained, is do you have a maximum of three possibilites, a b and c, or could the list be much much longer in which case the solution by @Astounding becomes cumbersome. So, @Ronein, please clear this up for us. The better information you give us, the better solutions you will get.

 

And please answer my original question, do you want the macro to realize that b is the second letter of the alphabet, and hence you get the second item in sequence in the title?????? Or not? These are very different situations. We can't advise you unless we know.

 

By the way, depending on your answer, I could envision a situation where macros ARE NOT NEEDED, and a much simpler solution is available, using BY groups in the analysis and the #Byval construct in your title. Again, let me repeat ... you MAY NOT NEED macros. There may be a MUCH SIMPLER solution. Please please please explain.

--
Paige Miller
Ronein
Meteorite | Level 14

Hello

Your code is not working I think.

Also after title statement should have quotes " "  and you dont have it in your code

 

 

Ron

ballardw
Super User

@Ronein wrote:

Hello

Your code is not working I think.

Also after title statement should have quotes " "  and you dont have it in your code

 

 

Ron


 

"is not working " is awful vague. And which code???

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Reeza
Super User

Some approaches:

1. A whole bunch of %IF/%THEN statements

2. A user defined format and apply it using %SYSFUNC

3. Manually set another set of macro variables that line with the same index. 

Ronein
Meteorite | Level 14
Hello
I just gave a simple example.
In reality it was more complicated.
The task is to change parameter value in title statement.
I have received an amswer to use if then statement within title statement.
Thank you so much

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