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é
Thanks a lot ..It worked 🙂
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;
Thanks a lot for your information ..It worked properly 🙂
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.
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;
Thanks a lot ..It worked 🙂
Thanks a lot it worked 🙂
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.