Search code examples
pdfsasods

Why have space in my text in my sas ods pdf


I want to make a pdf report in formula 1 GP, I have macro variables like the name of the GP, the year,... But in my pdf I have some space before or after my macro. I try to make some modification on my macro but without success. I put the result and a part of my code.

proc sql noprint;
  select trim(name) 
  into :gp_name
  from F1.race_data;
quit;

proc sql noprint;
  select trim(put(year , best.))
  into :gp_year
  from F1.race_data;
quit;

proc sql noprint;
  select trim(put(round , best.))
  into :gp_round
  from F1.race_data;
quit;

To make my pdf I have this

ODS PDF FILE= '/home/u59673531/SASII/Rapport_F1.pdf' style=rapport
    TITLE= 'Rapport GP F1'
    AUTHOR='ABC';
OPTIONS NODATE NONUMBER;
ODS ESCAPECHAR='^';
ODS PDF STARTPAGE=NEVER;

TITLE2 justify=LEFT  "Résumé du &gp_name";

ODS PDF TEXT="^{newline 1}";
ods text = "Voici le résumé du &gp_name sur le &gp_namegp pour le &gp_round e grand prix de la saison &gp_year se déroulant à &gp_local";

PROC PRINT DATA=F1.TABLE_GP NOOBS;
RUN;

And in my pdf I have this enter image description here

How I can resolve the problem with the space in my text ?


Solution

  • Use the TRIMMED option.

    TRIMMED trims the leading and trailing blanks from values that are stored in a single macro variable.

    proc sql noprint;
      select trim(name) 
      into :gp_name TRIMMED
      from F1.race_data;
    quit;
    

    EDIT:

    Example of doing multiple at once with formats.

    proc sql noprint;
    select name, 
           age, 
           today() format=worddate20.
    into :name TRIMMED, 
         :age TRIMMED, 
         :date TRIMMED
    from sashelp.class(obs=1);
    quit;
    
    %put |&name|;
    %put |&age.|;
    %put |&date.|;
    

    Last Edit:

    proc format;
      
       picture langtsfr (default=50) other='%d %B, %Y' 
                                     (datatype=date language=french);
    
    run;
    
    proc sql noprint;
    select name, 
           age, 
           '01SEP2023'd format=langtsfr.
    into :name TRIMMED, 
         :age TRIMMED, 
         :date TRIMMED
    from sashelp.class(obs=1);
    quit;
    
    %put |&name|;
    %put |&age.|;
    %put |&date.|;