BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
medic
Fluorite | Level 6

Hi all,

I'm trying to import multiple text files with comma(,) as delimiter, and make it as one dataset.

 

I refered to the following post and wrote a program as follows:

https://communities.sas.com/t5/General-SAS-Programming/read-in-multiple-txt-files-in-to-one-SAS-file...

 

 

my program:

 

filename file pipe 'dir D:\test\*.txt /s /b';
data test.t200_test;
	infile file truncover;
	input fname $100.;
	infile in filevar=fname end=last truncover dlm=',' firstobs=1;
	do until(last);
		input A $ B $ C $ D $;
		output;
	end;
run;

 

the problem I'm struggling is that in the data file, there are some missing values such as

123, A01, 20180401, 54321

234, , 20180401, 23412  ( <- missing data in the second column )

345, D31, 20180402, 12345

 

in this case, the dataset from the code above looks like

 

A   B     C     D

123  A01    20180401 54321

234  20180401  23412

345  D31    20180402 12345

 

which means, the program does not recognize that there's a missing value in second row of the column B, and just enters the value which is supposed to be in column C, and eventually leaving the last column empty.

But if there's no missing value on the next row, then the data is entered correctly again.

 

However, if I don't use this program and manually import the data files one by one using proc import procedure or import wizard, then there's no problem like this and becomes as what it should look like :

 

A   B     C     D

123  A01    20180401 54321

234  .         20180401 23412

345  D31    20180402 12345

 

 

Thank you in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Add the DSD option to your INFILE statement?

 

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Add the DSD option to your INFILE statement?

 

 

medic
Fluorite | Level 6
wow... Thank you sooooo much. It works now!!
I was struggling with this whole day T.T
Thanks a lot!!

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!

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
  • 2 replies
  • 1436 views
  • 1 like
  • 2 in conversation