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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2680 views
  • 2 likes
  • 3 in conversation