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 :
Thanks for any help 🙂
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;
Hi,
Use DATA step to read a csv file. You cannot control over the format in PROC IMPORT.
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;
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.