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

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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