BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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;
3 REPLIES 3
LinusH
Tourmaline | Level 20
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
deleted_user
Not applicable
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!
LinusH
Tourmaline | Level 20
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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