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