Hi,
I want to import a text-file that has 5 variables (gs, zbz, regs, rpara, wertn). Result with the Syntax1: Its importing the variables, but their content was cut off. Its strange, because I thought, thats not possible with DELIMITER=';'.
Do you know how to fix that? Thank you!
(The result of syntax2: SAs imports 5 variables, but without content)
Sntax1:
proc import datafile="[...].txt"
out=rkf
replace;
GETNAMES=yes;
DELIMITER=';';
run;
Syntax2:
data want;
infile "[...].txt"
dlm=";" dsd truncover;
input
gs $100
zbz $100
regs $100
Rpara $100
wertn $100;
run;
Have a look at the code below. If you want to execute you need to place a path that works for you.
%let path = your_folder_path;
proc export data = sashelp.cars(keep = drivetrain make model origin type)
outfile = "&path.class.txt"
dbms = dlm replace;
delimiter=';';
run;
/*Syntax1*/
proc import datafile = "&path.class.txt"
out = cars1
replace;
GETNAMES = yes;
DELIMITER = ';';
run;
/*Syntax2*/
data cars2;
length drivetrain $100 make $100 model $100 origin $100 type $100;
infile "&path.class.txt" dsd dlm = ";";
input make model type origin drivetrain;
run;
Have a look at the code below. If you want to execute you need to place a path that works for you.
%let path = your_folder_path;
proc export data = sashelp.cars(keep = drivetrain make model origin type)
outfile = "&path.class.txt"
dbms = dlm replace;
delimiter=';';
run;
/*Syntax1*/
proc import datafile = "&path.class.txt"
out = cars1
replace;
GETNAMES = yes;
DELIMITER = ';';
run;
/*Syntax2*/
data cars2;
length drivetrain $100 make $100 model $100 origin $100 type $100;
infile "&path.class.txt" dsd dlm = ";";
input make model type origin drivetrain;
run;
In the INFILE statement you told SAS to use a semicolon as the delimiter.
In the INPUT statement you told SAS to read the one byte in column 100 into each of the variables by using COLUMN MODE input, which will ignore the delimiter setting.
If the intent was to use the $100. informat then you need to include the period. But that will not work either because when you use FORMATTED MODE input the delimiter setting not have any effect.
You need to use LIST MODE input to read a delimited file.
Either define the variables first so you don't need the informats in the INPUT statement.
length
gs $100
zbz $100
regs $100
Rpara $100
wertn $100
;
input gs -- wertn ;
Or if you want to use an informat in the INPUT statement so that SAS can GUESS you want to define the variable to store more than 8 bytes then use the colon modifier before the informat. That will let INPUT know to use LIST MODE input instead of FORMATTED MODE input.
input
gs :$100.
zbz :$100.
regs :$100.
Rpara :$100.
wertn :$100.
;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.