BookmarkSubscribeRSS Feed
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

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

4 REPLIES 4
art297
Opal | Level 21

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;

JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

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

art297
Opal | Level 21

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;

art297
Opal | Level 21

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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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