BookmarkSubscribeRSS Feed
gsisme
Obsidian | Level 7

Hi,

I’m having an issue importing data using the ‘infile’ command. The issue seems too relate to the delimiter, however I cannot find a solution to the issue. I’ve even imported using File->Import and applied these settings however it still will not work. The reason I need to do it manually is that I have 2,500 files to import. Once the logic is fixed, I can nest the code inside a do loop and continue using a data dictionary.

I’ve included the first 5 column headers below; the first 4 will not populate in the output file, the 5th has the data from the first 4 columns bunched together.

 

data B._20121121;

     Informat iMonth BEST12.;

     Informat iYear BEST12.;

     Informat LEGAL_ENTITY_NUMBER BEST12.;

     Informat GL_ACCOUNT BEST12.;

     Informat COST_CENTER $20.;

 

     Format iMonth BEST12.;

     Format iYear BEST12.;

     Format LEGAL_ENTITY_NUMBER BEST12.;

     Format GL_ACCOUNT BEST12.;

     Format COST_CENTER $20.;

 

infile 'XXXXX

LRECL=3575

ENCODING="WLATIN1"

TERMSTR=CRLF

DLM='9F'x

MISSOVER

DSD ;

 

     Input iMonth: ?? BEST12.;

     Input iYear: ?? BEST12.;

     Input LEGAL_ENTITY_NUMBER: ?? BEST12.;

     Input GL_ACCOUNT: ?? BEST12.;

     Input COST_CENTER $;

     Input SECTOR_CODE $;

     Input card_assoc_id $;

 

 

run;

 

I've attached a sample of the output.

 

Does anyone have any ideas on how to proceed? Thanks.

3 REPLIES 3
gsisme
Obsidian | Level 7

Hi Kurt,

 

Thanks for the input. I've tried the above solution previously and it seems to duplicate the data from the 1st columns across the remainder of the table, with the exception of the very first observation which remains blank (see attached).

Kurt_Bremser
Super User

I copied your sample2.csv to our UNIX server and ran this:

data want;
infile '$HOME/sascommunity/Sample2.csv' dlm=',' dsd firstobs=2 truncover;
input
  iMonth
  iYear
  LEGAL_ENTITY_NUMBER
  GL_ACCOUNT
  COST_CENTER
;
run;

proc print data=want noobs;
run;

Result:

                  LEGAL_
  i        i     ENTITY_                   COST_
Month    Year     NUMBER    GL_ACCOUNT    CENTER

   .      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  
  11      11        11          11          11  

Contents of Sample2.csv, for reference:

iMonth,iYear,LEGAL_ENTITY_NUMBER,GL_ACCOUNT,COST_CENTER
.,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11
11,11,11,11,11

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 808 views
  • 0 likes
  • 2 in conversation