Help using Base SAS procedures

Changing title statement based on condition

Reply
Contributor
Posts: 70

Changing title statement based on condition

Does anzone help me out how to change the title stement in the output window based on condition

ex:%global x d;

      %let x=ccc;

      %let date=23may2014;

    data test;

     input var1 date;

     datalines;

     aaa 21may2014

     bbb 22may2014

     ccc 23may2014

     run;

     Title "................";

     proc print;

     run;

   Here i need if x=var1 and d=date then title="CCCCCCCCCCCCCCCCCCCCCC"

                     if x ne var1 and d=date   then title="BBBBBBBBBBBBBBBBBBBBB"

                     if  x ne var1 and d ne date then title="VVVVVVVVVVVVVVVVV";

Thanks in advance....

Super User
Super User
Posts: 7,430

Re: Changing title statement based on condition

Hi,

Use call execute in your datastep.

data ...;

     call execute('title "'||strip(your title)||'";');

     call execute('proc print...');

run;

Super User
Posts: 6,972

Re: Changing title statement based on condition

Since you cannot change the title while proc print is running, and you placed the condition on values of the dataset to be printed, your problem is unsolvable.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 9,691

Re: Changing title statement based on condition

Make a macro :


%global x d;
      %let x=ccc;
      %let date=23may2014;
       %let flag=N;
    data test;
     input var1 $ date :$20.;
      if var1="&x" then call symputx('flag','Y');
     datalines;
     aaa 21may2014
     bbb 22may2014
     ccc 23may2014
     run;
 %macro m;  
%if &flag eq Y %then %do; Title "YES.............."; %end;
       %else %do;title "NO....";     %end;
     proc print;
     run;
     %mend m;

     %m

Xia Keshan

Super User
Posts: 5,097

Re: Changing title statement based on condition

Well, you do have to understand that you have three observations, but there can only be one title.  Assuming you work out which of the three observations determines the title ...

You can create a macro variable holding the title's text, instead of writing a macro.  Right before the DATALINES statement, add along these lines:

if var1="&x" and d="&date" then call symput('text', 'CCCCCCCCCCCCCCCCCCCCCCC');

else if var1 ne "&x" and d="&date" then call symput('text', 'BBBBBBBBBBBBBBBBBBBBBBB');

else call symput('text', 'VVVVVVVVVVVVVVVVVVVVVVVVV');

Then below, your TITLE statement simply becomes:

title "&text";

Good luck.

Super User
Posts: 10,548

Re: Changing title statement based on condition

The closest you might get is to create your "title" variable and then

proc print;

by title;

run;

Depending on the version of SAS you are using there are options to modify the appearance of the By line that will appear before the printed data.

Contributor
Posts: 70

Re: Changing title statement based on condition

Hi all,

Thank you so much for your response.I tried all above,espesially programs by Ksharp and Astounding It was executed successfullz without anz errors,But it did not give the expected resulz.Itäs not able to change the title statement.Could zou guide me more please.

Thanks,

Rawindarreddy

Super User
Posts: 6,972

Re: Changing title statement based on condition

As was already stated, you CANNOT change the title during execution of a proc or data step. You can just try to simulate it.

One way to achieve the desired result is to generate the whole output manually with a data _null_ step. But this means you have to write the whole report syntax in eg html. Which takes knowledge in css, html and the intricacies of the put statement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 17,948

Re: Changing title statement based on condition

Post an example of what your data looks like and EXACTLY what you expect to see as the output and we can help you get there. The way your question is currently phrased it won't work, however there may be other solutions, some easier than others to get what you want.

Super User
Posts: 5,097

Re: Changing title statement based on condition

You will have to show more of your program.  What are all the details of your PROC PRINT?  What are you hoping will happen?

Ask a Question
Discussion stats
  • 9 replies
  • 333 views
  • 0 likes
  • 7 in conversation