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

Hi all,

 

i've a dataset like given bellow

N_363636
Mt_9581.17289791.52621366.1106
S_D2965.86262982.0749 398.3543

Now i need to give decimal places for the variables what if other variables contain more decimal places how to find out that .i had tried many things like format, length and etc. but it didn't work well.

is it really possible? if so, can anyone tell me how?

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You dont have a dataset like that, you can't have 36 as a variable name, nor can you have multiple of the same variable.  Please post test data in the form of a datastep in future:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

As such I can only speak generally in that:

data want;
  have=9581.1728;
  want=lenthn(scan(put(have,best.),2,"."));
run;

So I take the second word from the number after putting it to text, delimited by ., then lengthn() to get how many characters.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You dont have a dataset like that, you can't have 36 as a variable name, nor can you have multiple of the same variable.  Please post test data in the form of a datastep in future:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

As such I can only speak generally in that:

data want;
  have=9581.1728;
  want=lenthn(scan(put(have,best.),2,"."));
run;

So I take the second word from the number after putting it to text, delimited by ., then lengthn() to get how many characters.

ShiroAmada
Lapis Lazuli | Level 10

try this

data test;
  input amount 8.;
cards;
9581.1728
398.3543
12.12
1.12
;
run;

data want;
  set test;
  char=compress(amount||"","");
  len=length(char);
  dot=indexc(char,".");
  before=dot-1;
  after=len-dot;
run;

SAS Innovate 2025: Register Now

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!

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
  • 3 replies
  • 11341 views
  • 4 likes
  • 3 in conversation