Search code examples
sasstring-concatenationspace

how to concatenate several whitespace between two text strings


'I need add 6 blank spaces between variables a and b like:' 'Ive trie a lot of methods.'

data hh;

  %let texto1 = "Hola";
  length texto2 $8;
  texto2 = "   Mundo";
  %let texto3 = "!";
  length mi_variable $6; 
  mi_variable = "      ";
  
  z = cats(&texto1., mi_variable, &texto3.);
d= "a"&"b";
e = catx(' ', "a", "      ", "b");
f = cat("a", repeat(" ", 6), "b");
g = "a" || repeat(" ", 6) || "b";
h = catx(" ", "a", repeat(" ", 6), "b");
run;

proc print data=hh;run;

'The outpus is always :' 'a b'

'im expexting this:' 'a b'


Solution

  • Is this what you are trying to do? I use CATX first arg of 6 spaces.

    21   data _null_;
    22       length texto1-texto2 $8 result $24;
    23       texto1 = "Hola";
    24       texto2 = "Mundo";
    25       result = catx('      ',of texto:);
    26
    27       put (_all_)(=);
    28       put 'NOTE: ' result $char.;
    29       put 'NOTE- ' result $hex.;
    30       run;
    
    texto1=Hola texto2=Mundo result=Hola      Mundo
    NOTE: Hola      Mundo
          486F6C612020202020204D756E646F202020202020202020
    NOTE: DATA statement used (Total process time):
          real time           0.00 seconds
          cpu time            0.01 seconds