SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Right justify numeric with character

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Right justify numeric with character

Hello everybody.

 

I would like to make 100 string variables card1-card100 so that card1=001... card10=010...card100=100.

Ideally a function that justifies right 'i' with '0' as fiiler character should be used. I tried right() but couldn't make it work.

 

What I then tried was

 

array card{100} card1-card100;
do i=1 to 100;
    if i in (1:9) then card{i}='00'||i;
    if i in (10:99) then card{i}='0'||i;
    if i=100 then card{i}='100';    
end;

but this won't work either.

 

Any ideas?

 

Thanks in advance.

 

P.S. I am on SAS 9.4


Accepted Solutions
Solution
‎06-28-2016 10:16 AM
Super Contributor
Posts: 394

Re: Right justify numeric with character

data;
array card{100} $3 card1-card100;
do i = 1 to 100;
    card{i} = put(i, z3.);
    put card{i};
end;
run;

View solution in original post


All Replies
Super Contributor
Posts: 394

Re: Right justify numeric with character

Use the Zw.d format.

Occasional Contributor
Posts: 12

Re: Right justify numeric with character

Hi Tim.

 

I use

array card{100} card1-card100;
do i=1 to 100;
	card{i}=put(i,z3.);
end;

but it gives card1=1, card2=2, ..., card100=100, 

 

not card1=001, card2=002, ..., card100=100, 

Solution
‎06-28-2016 10:16 AM
Super Contributor
Posts: 394

Re: Right justify numeric with character

data;
array card{100} $3 card1-card100;
do i = 1 to 100;
    card{i} = put(i, z3.);
    put card{i};
end;
run;
Occasional Contributor
Posts: 12

Re: Right justify numeric with character

[ Edited ]

Thanks again Tim.

 

It even worked as

array card{100} $ card1-card100;
do i=1 to 100;
	card{i}=put(i,z3.);
end;

$ was the missing part..

 

Kind regards.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 287 views
  • 0 likes
  • 2 in conversation