Desktop productivity for business analysts and programmers

Urgent: How to modify the variable type (character or numeric)

Reply
N/A
Posts: 0

Urgent: How to modify the variable type (character or numeric)

When I inport CSV files into SAS EG by SAS code (as below), the type of the variables are changed from numeric to character. How can I modify the type by code?


PROC IMPORT
DATAFILE= "/home/&MONTH..csv"
OUT= CPMS.&MONTH REPLACE;
GETNAMES=NO;
RUN;


DATA &MONTH;
SET &MONTH
(RENAME =
(var1 = CUSTOMERID
var2 = CUSTOMERNAME
var3 = TOT_LIMIT));
MONTH = &MONTH;
where Customerid <> 999;

RUN;
Esteemed Advisor
Posts: 5,198

Re: Urgent: How to modify the variable type (character or numeric)

If you don't have mixed datatypes in your intended numerical column, PROC IMPORT should be able to set the column to numeric.

To change (or rather to convert the contents to be stored in a new column) a char column to numeric in the data step, use the INPUT function.

/Linus
Data never sleeps
N/A
Posts: 0

Re: Urgent: How to modify the variable type (character or numeric)

Thanks Linus.

Is this type (eg.1,396,123.05) are mixed datatype? All the variable in this type are converted into character.

Actually, I need to import a set of CSV files (around 50 files), which have different combination of variables (around 20 combinations).It is very time consuming to use INPUT function to input files one by one.

Is there any other mrthod? Thanks so much!
Esteemed Advisor
Posts: 5,198

Re: Urgent: How to modify the variable type (character or numeric)

Not mixed, but it's formatted numerical data, that PROC IMPORT will interpret as CHAR. Unfortunately PROC IMPORT does nor support INFORMAT, and I'm not aware of any generic way to set a INFORMAT as default. If you have a name standard for columns with these formatted values, you may do some macro coding.

The alternative is when using EG, you can specify informats during import (this beacuse EG does not use PROC IMPORT). But this will be per file basis...


/Linus
Data never sleeps
Ask a Question
Discussion stats
  • 3 replies
  • 117 views
  • 0 likes
  • 2 in conversation