BookmarkSubscribeRSS Feed
LearnByMistk
Obsidian | Level 7

How to check tab delimited file metadata before importing in sas via proc import ,I mean suppose I write a proc import with columns a,b,c with their informat and format in place but in second data refresh if I get a new column D ,how to check it before proc import fails.

3 REPLIES 3
Kurt_Bremser
Super User

proc import (most probably) won't fail, as it always does its best to make sense of input data, but the result will not match your previous results (structurally).

The proper method for handling such issues is that you have an agreement in place where the structure of files is described, and the agreement has to be changed and communicated so that import steps can be adapted. Production import steps have to be data steps that have the file structure hardcoded, no proc import there.

andreas_lds
Jade | Level 19

Afaik tab-delimited files don't have any metadata in them.

Proc import does not allow to set (in)formats, so you will have to use a data step.

Tom
Super User Tom
Super User

You can read the header line and check.

Say your input file is NEWCSV and expected structure is described by the SAS datasets TEMPLATE.

* Read headers from new delimited file ;
data new_names ;
  length name $50 ;
  infile newcsv obs=1 dsd dlm='09'x ;
  input name @@ ;
run;

* Get names from template structure ;
proc transpose data=template(obs=0) out=old_names;
  var _all_;
run;

* Compare;
proc compare data=old_names compare=new_names;
run;

PROC COMPARE will actually set a macro variable you can test to see if there are differences.  Or you can use some other methods to compare.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 638 views
  • 2 likes
  • 4 in conversation