BookmarkSubscribeRSS Feed
smg3141
Obsidian | Level 7

I have 2 .BCP files I am trying to import into SAS. I used proc import, but the date variables changed format. I would like to figure out the length of each variable so I can import using inline. Is there a way to determine the lengths of the variables in the .BCP file?

4 REPLIES 4
japelin
Rhodochrosite | Level 12

PROC IMPORT cannot determine the length.

Access dictionary table to figure out the length of variables after import.

For example.

data _null_;
  set sashelp.vcolumn;
  where LIBNAME="SASHELP" and MEMNAME="CLASS";
  put libname memname name length;
run;

proc sql;
   select libname, memname, name, length  
   from DICTIONARY.COLUMNS
   where LIBNAME="SASHELP" and MEMNAME="CLASS";
quit;
andreas_lds
Jade | Level 19

BCP? Never heard of it. Please explain.

If those files are text-files, you must have documentation of the structure, if not ask for one. Guessing types, lengths and informats is the best way to create more work in the long-run.

Patrick
Opal | Level 21

From the Microsoft documentation https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15 

Patrick_0-1652434553905.png

So I guess you would eventually want the format file as well. But then because you're not importing into a SQL server you would then also need to write a program that maps the SQL server data types and attributes to the appropriate SAS data types and attributes (like the right informat for any date and datetime values).

 

Ideally connect directly to the SQL server and export the data this way. Or then try to get the data as JSON files and not as .bcp

Tom
Super User Tom
Super User

It really depends on what is in those files.

From the documentation page linked by an earlier reply you might be lucky and they are just simple tab delimited files.

 

-c
Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type, without prefixes and with \t (tab character) as the field separator and \r\n (newline character) as the row terminator. -c is not compatible with -w.

LOOK at the file and see what you have.

Check to see if they are text files with lines by looking at the first 5 lines.

filename BCP 'myfilename.bcp';
data _null_;
  infile bcp obs=5;
  input;
  list;
run;

Or look at them a binary files.  To check the first 500 bytes you could use:

data _null_;
  infile bcp recfm=f lrecl=100 obs=5;
  input;
  list;
run;

 

 

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
  • 4 replies
  • 537 views
  • 0 likes
  • 5 in conversation