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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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