Help using Base SAS procedures

right/left justified variables

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 444
Accepted Solution

right/left justified variables


i have a char variable that need to be filled with |||| to the left and 2 zeros to the right

and write to an output file with  a length of 19 (pos 2 to position 20)

so if the variable is "aaaaaaaaaa"

then it needs to be displayed as    |||||||aaaaaaaaaa00

The zeros  are easy to be added  but the ||| no clue

also another char var (length=16) that needs to be right justified with zeros

so it the var is bbbbbbbbbb it will be 000000bbbbbbbbbb  in the  output

anyone please Smiley Happy


Accepted Solutions
Solution
‎09-17-2014 05:06 PM
Respected Advisor
Posts: 3,156

Re: right/left justified variables

I am sure there will be many solutions, here is two of them, _var1--tranwrd() and _var2--substr()

data test;

length _var1 var1 _var2 $ 19;

var="aaaaaaaaaa";

var1=cats(var,'00');

_var1=tranwrd(right(var1),' ','|');

_var2=repeat('|',18);

substr(_var2,19-length(var)-2)=cats(var,'00');

run;

Regards,

Haikuo

Or _var3:

_var3=cats(repeat('|',19-length(var)-3),var,'00');

View solution in original post


All Replies
Solution
‎09-17-2014 05:06 PM
Respected Advisor
Posts: 3,156

Re: right/left justified variables

I am sure there will be many solutions, here is two of them, _var1--tranwrd() and _var2--substr()

data test;

length _var1 var1 _var2 $ 19;

var="aaaaaaaaaa";

var1=cats(var,'00');

_var1=tranwrd(right(var1),' ','|');

_var2=repeat('|',18);

substr(_var2,19-length(var)-2)=cats(var,'00');

run;

Regards,

Haikuo

Or _var3:

_var3=cats(repeat('|',19-length(var)-3),var,'00');

Super Contributor
Super Contributor
Posts: 444

Re: right/left  justified variables

thanks Haikuo!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 216 views
  • 1 like
  • 2 in conversation