DATA Step, Macro, Functions and more

Removing currency symbol, replace missing with "NA"

Reply
Occasional Contributor
Posts: 15

Removing currency symbol, replace missing with "NA"

[ Edited ]

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)

Super User
Posts: 7,846

Re: Removing currency symbol, replace missing with "NA"

[ Edited ]
Posted in reply to sas_viclearner

"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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,981

Re: r coding for sas project

Posted in reply to sas_viclearner

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.

Occasional Contributor
Posts: 15

Re: Removing currency symbol, replace missing with "NA"

[ Edited ]

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.

Super User
Posts: 7,846

Re: Removing currency symbol, replace missing with "NA"

Posted in reply to sas_viclearner

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 104 views
  • 0 likes
  • 3 in conversation