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

Hi Guys,

 

I have this data step:

 

And I want to convert last field - sequence of **i** value to char:

data one;
array c {25} $ ('00' '01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24');
*c{i}=put(c{i},$2.); ** I tried with this and it does not work**
do i='00' to '24';
output;
end;
run;

 

After execution of data step, I got this in the last field:

i

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

 

and I want:

i

00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

 

I tried to convert that sequence number in char and I was not able to.

The scope of this that I want to use this **char** sequence like a macro variable.

 

Do you have some work around on this??

 

Thanks and regards,

José

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jcorti
Obsidian | Level 7

Thanks a lot ..It worked 🙂

View solution in original post

6 REPLIES 6
ballardw
Super User

If you have a NUMERIC variable that you want to display with leading zeroes you do not need to create a text variable you can use a Z format to provide them.

 

or possibly what you want is

data one;

   array c{25} $;

   do i=0 to 24;

      c[i] = put (i, z2.);

      output;

    end;

    drop i;

run;

Jcorti
Obsidian | Level 7

Thanks a lot for your information ..It worked properly 🙂

Kurt_Bremser
Super User

The iteration variable from the do statement is always numeric, so either use a Zw. format for display, or do

data want (keep=i);
do i1 = 1 to 24;
  i = put(i1,z2.);
  output;
end;
run;

to get a character variable in your dataset.

ballardw
Super User

Minor correct to @Kurt_Bremser, an iterated do loop will accept an explicit list of values separated by commas but will not all the From - To-(and especially By).

data junk;
   do c='00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24';
      output;
   end;
run;
Jcorti
Obsidian | Level 7

Thanks a lot ..It worked 🙂

Jcorti
Obsidian | Level 7

Thanks a lot it worked 🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 3073 views
  • 2 likes
  • 3 in conversation