BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CaroleBPRI
Calcite | Level 5

Hi,

 

I imported a csv file with the following code :

proc import out=GSM
datafile='V:\3613_DEPT_CONTROLE_DE_GESTION\Transverse\ANAPLAN\PALLIATIFS_DIRECT_PBI\commissions\GSM.csv'
DBMS=csv
replace;
delimiter = ";";
run;

 

In the GSM.csv file, one column is "Comax Code" and the format is character. For example, "0000001"

 

SAS put automatically an informat : numeric and "0000001" become the number 1

 

To fix that I try :

proc import out=GSM
datafile='V:\3613_DEPT_CONTROLE_DE_GESTION\Transverse\ANAPLAN\PALLIATIFS_DIRECT_PBI\commissions\GSM.csv'
DBMS=csv
replace;
delimiter = ";";
informat "Comax Code" $8.;
run;

 

But I still have the wrong informat : 

CaroleBPRI_0-1689086533156.png

 

Thanks for any help 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
john_mccall
SAS Employee

You can consider changing wihtthe data step following Proc iMport:

proc import out=GSM
datafile='V:\3613_DEPT_CONTROLE_DE_GESTION\Transverse\ANAPLAN\PALLIATIFS_DIRECT_PBI\commissions\GSM.csv'
DBMS=csv
replace;
delimiter = ";";
run;

Data GSM;

    set GSM(rename=(ComaxCode=CC));

    ComaxCode=put(CC,z7.);

drop cc;

run;

 

View solution in original post

3 REPLIES 3
A_Kh
Lapis Lazuli | Level 10

Hi, 

 

Use DATA step to read  a csv file. You cannot control over the format in PROC IMPORT. 

john_mccall
SAS Employee

You can consider changing wihtthe data step following Proc iMport:

proc import out=GSM
datafile='V:\3613_DEPT_CONTROLE_DE_GESTION\Transverse\ANAPLAN\PALLIATIFS_DIRECT_PBI\commissions\GSM.csv'
DBMS=csv
replace;
delimiter = ";";
run;

Data GSM;

    set GSM(rename=(ComaxCode=CC));

    ComaxCode=put(CC,z7.);

drop cc;

run;

 

ballardw
Super User

Proc Import for text files such as CSV will create data step code. Look in your log.

You can copy that generated code, paste it into the editor, clean  it up a bit (remove line numbers) and then change the properties of the variables by changing the Informat statement generated for your variables.

 

IF you are going to read multiple files with the same structure I would suggest saving that data step and likely making character variables 5 to 10 characters longer to accommodate other data files with longer values. Then you just modify the Infile statement to point to the new source file and change the output data set name as needed.

 

Depending on your data you might also consider cleaning up variable names and adding labels to variables.

You can likely drop most of the Format statements accept for date, time or datetime values.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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