Sigh (for the FOCUS to SAS conversion)!
Here are a few ideas:
[pre]
%let blanks = %str( );
proc sql;
create table newone as
select name ,
age,
height,
right(put(name,$11.)) as newfield1 format=$11.,
put(name,$11.) as newfield2 format=$11.,
"&blanks"||name as newfield3 format=$11.,
' '||name as newfield4 format=$11.
from sashelp.class;
quit;
proc print data=newone label split='*';
label newfield1 = 'newfield1*1...5....0.'
newfield2 = 'newfield2*1...5....0.'
newfield3 = 'newfield3*1...5....0.'
newfield4 = 'newfield4*1...5....0.';
run;
[/pre]
NEWFIELD1 uses a PUT statement to ensure that the variable has a length of 11 AND that the values are right-justified in the field
NEWFIELD2 uses a simple PUT statement and you can see that the length is 11, but the extra spaces are all put at the end of the field
NEWFIELD3 uses a macro variable and a concatenate to prepend 3 spaces to the value of the field (and the new length is 11)
NEWFIELD4 uses a simple concatenate to prepend 3 spaces to the value of the field (and the new length is 11)
Depending on your desired results, any of the ways that are shown in the sample code should work for you. The original length of the NAME field in SASHELP.CLASS is 8 characters or positions. So when you look at the output, remember that "short" names like Sue or Alfred will also have trailing spaces at the end (with methods 2, 3 or 4) -- the number of trailing spaces will be different.
In your code, seem to have just one quote around your macro variable &threeblanks ("&threeblanks) -- which would be wrong. I think the simple:
[pre]
' '||name as newfield4 format=$11.
[/pre]
will work for your case without needing macro variables. I used a %STR macro function to delimit my 3 spaces, but I think the simple example will work without needing a macro variable.
Only one thing bothers me in your post and that is the statement that places in the FOCUS program use the field with 3 leading blanks. I hope you meant use the field VALUE with 3 leading blanks and NOT the field NAME with 3 leading blanks. A SAS variable or column or field name does not normally contain spaces. So, for example in SASHELP.CLASS, the field or column AGE contains the VALUE 14 for the first observation, where NAME=Alfred. So my examples all show how to put the 3 spaces in front of the field VALUE.
The only other thing I'm wondering is HOW you're going to use your newfield column. Are there comparisons where you need to do this:[pre]
where newfield = ' Alfred'; versus
where newfield='Alfred';
[/pre]
Here's an example of doing comparisons to consider:
[pre]
data testit;
length name $11;
name = 'Alfred ';
output;
name = 'Percival ';
output;
name = ' Alfred ';
output;
name = ' Alfred';
output;
name = 'Alfreda ';
output;
run;
proc print data=testit;
title 'looking at everybody';
run;
proc print data=testit;
title 'using colon modifier to limit comparison';
where name=: ' Alfred';
run;
proc print data=testit;
title 'using string';
where name = 'Alfred';
run;
proc print data=testit;
title 'using LEFT(NAME)';
where left(name) = 'Alfred';
run;
proc print data=testit;
title 'using CONTAINS';
where name contains 'Alfred';
run;
[/pre]
Hope this helps,
cynthia