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;
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?
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.