Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change Data Type?

Status
Not open for further replies.

izaretsky

Programmer
Apr 28, 2008
1
US
Hi. I am newbe in SAS.
I ran into the following problem and cannot find an answer.

I am downloading .csv file into new SAS table.

Column Col_1 becomes a string($15.) automatically because
values are: 1.223 or 0.45 or 'N/A' or 'XXX'.
I understand this OK.

I need to come up with the table that has Col_1 with number format where only float values are included.

All rows that do not have proper data ('N/A', 'XXX') should be deleted or not included.

My question is: How to do it in SAS?
It would be nice if you provide some kind of samle...

I appriciate your help.
Thanks.
 
There's a couple of ways of doing this. The simplest (but not necessarily best) is this:-
Code:
  col_1_fixed = input(col_1,10.3);

This will generate warnings where col_1 contains things that aren't numbers though, and I dislike that.
The alternative is this:-
Code:
  if col_1 not in('N/A','XXX') then
     col_1_fixed = input(col_1,10.3);
which will skip the errors, leaving missing values in col_1_fixed for those bad values.
To drop records which have invalid values do this:-
Code:
  if col_1 not in('N/A','XXX') then
     col_1_fixed = input(col_1,10.3);
  else delete;


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top