This is certainly a rather unusual request and I assume you want to do this for some reporting/indention.
You can easily add leading blanks just by concatenating such blanks to the variable BUT depending on the procedure and especially the output destination used these leading blanks might still not print as you'd like it.
Consider the following code:
data test;
length var2 var3 $10;
format var3 $char10.;
var='abcd';
var2=' '||var;
var3=' '||var;
run;
ods listing;
proc print data=test;
run;
Listing destination:
HTML destination (the SAS EG default):
So if this is about reporting/printing then eventually it's more about using styles instead of adding blanks to the internal value of SAS variables.
Let us know a bit more in detail what you have and what you need and we can go from there.
Is the variable long enough to store five additional chars? Something like this should do:
var = cat(repeat(' ', 4), var);
Please note, that html and log may hide those leading spaces.
This is certainly a rather unusual request and I assume you want to do this for some reporting/indention.
You can easily add leading blanks just by concatenating such blanks to the variable BUT depending on the procedure and especially the output destination used these leading blanks might still not print as you'd like it.
Consider the following code:
data test;
length var2 var3 $10;
format var3 $char10.;
var='abcd';
var2=' '||var;
var3=' '||var;
run;
ods listing;
proc print data=test;
run;
Listing destination:
HTML destination (the SAS EG default):
So if this is about reporting/printing then eventually it's more about using styles instead of adding blanks to the internal value of SAS variables.
Let us know a bit more in detail what you have and what you need and we can go from there.
Thank you @Patrick for the quick response. I was also thinking on the same lines but it was not working at that time. However, after sometime the solution given by you worked, however, I had not seen your response at that time. It just worked (maybe there was some other issue) and now I am seeing your response. Thanks a lot once again for the quick response. It is surely helpful.
- Dr. Abhijeet Safai
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.