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

Hi  friends,

I have the  problem.

and

   I have the sas data set like this

emp_details             value

sal                          5,25,369

HRA                       10.2%

PF                           5%

TAX                         1%

LIC                          10%

OTHER_INCOME     60,500

OTHER_SAVES       .

TA                            0

HERE emp_details AND value  BOTH ARE CHARACTER DATA TYPE .,


I WANT CONVERTING value VARIABLE  CHARACTER TO NUMERIC.

AND ALSO GET THE SAME FORMATS




emp_details             value

sal                          5,25,369

HRA                       10.2%

PF                           5%

TAX                         1%

LIC                          10%

OTHER_INCOME     60,500

OTHER_SAVES       .

TA                            0

HERE VALUE IS THE NUMERIC DATA TYPE

PLZ  HELP ME

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

data have;

input emp_details   : $20.          value : $20.;

cards;

sal                          5,25,369

HRA                       10.2%

PF                           5%

TAX                         1%

LIC                          10%

OTHER_INCOME     60,500

OTHER_SAVES       .

TA                            0

;

run;

proc format;

value fmt

  low-0,1-high=[comma32.]

  other=[percent8.]

  ;

run;

data want;

set have;

length fmt $ 20;

if find(value,'%') then fmt='percent12.';

  else fmt='comma32.';

v=inputn(strip(value),fmt);

format v fmt.;

run;

View solution in original post

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

Please don't type in capitals.  You can't directly convert each of those text items to numeric as they do not contain the same type of data, hence why they are character in the first place.  A format is something which applies to the whole of a column, so to apply percentage will set that format on every cell in that column.  SAS is not Excel.  SAS works on the concept of datasets with fixed structure columns.

Now the second question is why you need to put them into numeric?  Is it to do further processing on the data?  If so then create separate columns for each type of data, i.e. one for percentages, one for numbers.  Then process then and return the processed information back to character to create one column.  E.g

emp_details          value          num_val          perc_val

HRA                     5,25,369     525369          

PF                        5%                                   5

...

Then cats(put(num_val,comma8.),put(perc_val,percent8.)).

Ksharp
Super User

data have;

input emp_details   : $20.          value : $20.;

cards;

sal                          5,25,369

HRA                       10.2%

PF                           5%

TAX                         1%

LIC                          10%

OTHER_INCOME     60,500

OTHER_SAVES       .

TA                            0

;

run;

proc format;

value fmt

  low-0,1-high=[comma32.]

  other=[percent8.]

  ;

run;

data want;

set have;

length fmt $ 20;

if find(value,'%') then fmt='percent12.';

  else fmt='comma32.';

v=inputn(strip(value),fmt);

format v fmt.;

run;

tlnarayana26
Calcite | Level 5

code is working sir.

thank you

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1104 views
  • 0 likes
  • 3 in conversation