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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
JosvanderVelden
SAS Super FREQ

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;

View solution in original post

2 REPLIES 2
JosvanderVelden
SAS Super FREQ

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;
Tom
Super User Tom
Super User

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 841 views
  • 1 like
  • 3 in conversation