Extract left part of the string in SAS?

staq picture staq · Oct 14, 2014 · Viewed 29.8k times · Source

Is there a function SAS proc SQL which i can use to extract left part of the string.it is something similar to LEFT function sql server. in SQL I have left(11111111, 4) * 9 = 9999, I would like to something similar in SAS proc SQL. Any help will be appreciated.

Answer

vasja picture vasja · Oct 14, 2014

Had an impression you want to repeat the substring instead of multiply, so I'm adding REPEAT function just for the curiosity.

proc sql;
select 
  INPUT(SUBSTR('11111111', 1, 4), 4.) * 9            /* if source is char */
, INPUT(SUBSTR(PUT(11111111, 16. -L), 1, 4), 4.) * 9  /* if source is number */
, REPEAT(SUBSTR(PUT(11111111, 16. -L), 1, 4), 9)      /* repeat instead of multiply */
FROM SASHELP.CLASS (obs=1)
;
quit;