BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need to create a variable with some values containing leading values. 

output needed in dataset 'two'  for variable 'c'

c

all

  aaa

  bbb

  ddd

 

In the above output,  i need to have leading blanks for all except first value 'all'.     Please suggest. Thank you


data one; input a b$; datalines; 1 all 2 aaa 3 bbb 4 ddd ; data two; set one; if a=1 then c=a; else c= a; run;

 

 

3 REPLIES 3
heffo
Pyrite | Level 9

If you just want a leading space I would use the cat function. I would also use strip to make sure that there are no spaces to begin with in the variable a. 

data two;
set one;
if a=1 then c=a;
else c=  cat(" ",strip(a));
run;

Or am I missing something more?  

Reeza
Super User
What do you need the leading blanks for? PROC REPORT now has an indent option within the style or somewhere at least that can control indents.
Kurt_Bremser
Super User

Blanks in code are never blanks in data. Blanks in code are just separators between code elements. To have blanks as data, you need to make that clear to the data step compiler by using quotes and the proper concatenation operator:

a = "  " || a;

Note that this may cause the truncation of the values in a.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1106 views
  • 2 likes
  • 4 in conversation