BookmarkSubscribeRSS Feed
rawindar
Calcite | Level 5

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....

9 REPLIES 9
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Use call execute in your datastep.

data ...;

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

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

run;

Kurt_Bremser
Super User

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.

Ksharp
Super User

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

Astounding
PROC Star

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.

ballardw
Super User

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.

rawindar
Calcite | Level 5

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

Kurt_Bremser
Super User

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.

Reeza
Super User

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.

Astounding
PROC Star

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 2018 views
  • 1 like
  • 7 in conversation