SAS Programming

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

Hi Team,

I have a csv file in which some columns( example column A) has $ value and column B has (0 value). How can i remove $ symbol for column A and convert the column B value to numeric(NA)

4 REPLIES 4
Kurt_Bremser
Super User

"Community Matters" is for things concerning the working of this community, so i moved your post to Base SAS programming.

Consider a better subject line, as I see nothing concerning R here.

Please post an example of your csv data (use the {i} icon for posting text that must not be reformatted), and what you expect as data in a SAS dataset. NA is not a valid numerical value, but you might want to set zeroes to missing values in SAS.

 

Edit: changed subject to the edited subject line of the original post.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your post is unclear.  Where does the R from the subject title come in?

To get rid of $ just do:

a=compress(a,"$");

For b, not sure what you mean, NA is not a numeric, nor could be a numeric.  You can fool it by using a format:

proc format;
   value temp
      0="NA";
run;

And apply that to the number, however the number will still be 0 behind the scenes.  Always a good idea to post test data and required output in your questions to illustrate problems, and post what code you have.

sas_viclearner
Fluorite | Level 6

In the diagram  Columns A,B,C, D has $ symbol for currency, i need to get rid of them. And some of the values are missing which are shown as blank, i need to replace those blank with NA not a numericR SAS.JPG

 

 

Edit [KB]: adapted the subject line.

Kurt_Bremser
Super User

Read (or convert) with the DOLLARw.d informat:

data have;
infile cards truncover;
input inval $;
cards;
$17.00
 
$20.23
;
run;

data want;
set have;
outval = input(inval,dollar10.);
format outval dollar10.2;
run;

proc print data=want noobs;
run;
inval         outval

$17.00        $17.00
                 .  
$20.23        $20.23

You can see how the empty value results in a missing numeric SAS value, which is the correct way to handle this.

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