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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.