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
Given this structure to the program, I would replace the existing TITLE statement with:
Title
%if ¶m=a %then '0-20';
%else %if ¶m=b %then '20-40';
%else %if ¶m=c %then '40+';
;
For a limited number of values, %IF/THEN handles it well.
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)
The most simple way is to assign 2 macro variables
when mac1 = a then mac2 = Group2
etc.
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.
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 “¶m1.”;
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_¶m1. AS
SELECT count(*) as NoObs
FROM tbl2
WHERE Ind=¶m1.
QUIT;
Title “¶m1.”;
Proc print data= Summarry_¶m1. Noobs;
Run;
%end;
%mend test;
Given this structure to the program, I would replace the existing TITLE statement with:
Title
%if ¶m=a %then '0-20';
%else %if ¶m=b %then '20-40';
%else %if ¶m=c %then '40+';
;
For a limited number of values, %IF/THEN handles it well.
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.
Hello
Your code is not working I think.
Also after title statement should have quotes " " and you dont have it in your code
Ron
@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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.