BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9


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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

2 REPLIES 2
Haikuo
Onyx | Level 15

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');

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thanks Haikuo!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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