SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
sasowiczka123
Fluorite | Level 6

Hello, 
During analyzing financial data I came across a huge difficulty.  Variable "total salary" looks like this:

75,879.00 or 123,679.00 or 7,987.00. Do you know how to delete commas and periods? They occure in different places.

Please help

5 REPLIES 5
Reeza
Super User
What is the type and format applied on that variable? Is this after you've imported the data or something you're trying to do after you've imported the data?
ballardw
Super User

Please describe what you are doing that the presence of either the comma or the decimal affects your analysis.

 

You may also want to run proc contents on that data set and share the variable type and format currently associated with the variable.

I suspect that the current format is some form of CommaW.D. The presence of the commas or decimals are very unlikely to have any impact on analysis though possible will have an effect on some reports.

Shmuel
Garnet | Level 18

What is the origin of your data? is it excel or any other external file or data base?

How do you import that file into sas?

I believe that the issue is the result of method importing the data to sas.

biopharma
Quartz | Level 8

What is the variable type? Numeric that is formatted to display such or a character variable containing the above strings? Don't think you want to remove the period without also removing the zeroes that follow. Otherwise, it affects the value.

 

If it is a numeric variable type you can clear the format with:

format <variable> ;

 

If it is character, you can compress the comma out. I don't think you should delete the period as it would change the value. Here is a small demo:

 

900        data _null_ ;
901          x = "123,679.00" ;
902          y = compress(scan(x,1,".")) ;
903          put x = y = ;
904        run ;
 
x=123,679.00 y=123,679

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 5 replies
  • 6673 views
  • 0 likes
  • 6 in conversation