DATA Step, Macro, Functions and more

Adding Leading Blank to specific Observation

Reply
New User
Posts: 1

Adding Leading Blank to specific Observation

How can I add a leading blank to selected observation of a variable.

Super User
Posts: 10,020

Re: Adding Leading Blank to specific Observation

Posted in reply to mgowtham24

As long as your variable's length is long enough, you can use :

have='  '||have;

Otherwise you need expand its length long enough.

length want $ 200;
want='  '||have;
Occasional Contributor
Posts: 18

Re: Adding Leading Blank to specific Observation

Posted in reply to mgowtham24

Hi,

 

You can align it to Right so that it will have leading blanks. But will it solve your query.Could you please elaborate your exact problem with more details. Following code can align value of selected variable to right.

 


data person;
infile datalines delimiter=',';
input name $ dept $ value value1;
datalines;
John,Sales,-200,200
Mary,Accounts,-500,300
Johny,Sales,-200,200
Mak,Accounts,-100,100
;
run;

data person;
set person;
name=right(name);
dept=right(dept);
run;

Ask a Question
Discussion stats
  • 2 replies
  • 163 views
  • 1 like
  • 3 in conversation