How do I read individual numeric values of 31415?
This is how my dataset to look like:
Digits
3
1
4
1
5
Regards,
JAR
I think your question may have gotten lost in its presentation. Are you asking how one would do the following:
data have;
input (x1-x5) (1.);
cards;
31415
;
run;
Say, I need value of pi. This one-variable dataset contains only digits of pi.
However, the raw data contains value of pi as a string 314159265.... How do I do it?
Regards,
JAR
There are a number of ways. One, for example, might be to use code like:
data have;
input x;
cards;
3
1
4
1
5
9
2
6
5
;
run;
data want;
set have end=last;
retain hold;
if _n_ eq 1 then hold=catt(x,'.');
else hold=catt(hold,x);
if last then do;
pi=input(hold,best12.);
output;
end;
run;
Of course, since there wasn't a decimal place in your example data, I had to force one in as part of the code. However, if all you wanted was the value of pi, the following would be a much easier way to go:
data easier;
pi=constant('pi');
run;
Just in case I have still misinterpreted what you asked, if you do have a one variable, one record dataset, with one string, how about?:
data have;
input x $9.;
cards;
314159265
;
run;
data want;
set have end=last;
pi=input(x,best12.8);
/* or if you want it as a macro variable
for use in other datasteps */
call symput('pi',pi);
run;
data test;
input x;
x_times_pi=x*&pi.;
/* or using the bulit-in constant */
x_times_pi_using_constant=x*constant('pi');
cards;
2
3
;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.