BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

Hello,

 

Any methods to reacd external files in SAS except INFILE ??

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Would it qualify as not using INFILE if the external file had a "datalines;" statement as its first line.  If so, then such a file can be %INCLUDEd (like c:\temp\t.txt below in the second data step.  

 

filename f 'c:\temp\t.txt';
data _null_;
  file f;
  put 'datalines;';
  put '1 1 1';
  put '2 2 2';
run;

data t;
  input a b c;
  %include 'c:\temp\t.txt';
run;

Those who are facile with their operating system commands can probably create a pipe with the "datalines;" statement dynamically inserted before streaming the file in question.  Then just %INCLUDE the pipe.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

@Aexor wrote:

Hello,

 

Any methods to reacd external files in SAS except INFILE ??

 


PROC IMPORT can be used to convert external files into SAS datasets.  Check the documentation for the types of files it can read.  Typically you use this to convert data that looks like a dataset, like a spreadsheet (Excel files for example), another database (dBASE, SPSS, STATA, etc)

ballardw
Super User

SAS/Access has modules to connect to many data sources.

 

ODBC can be used to connect to some.

 

The LIBNAME can also connect to some file types.

mkeintz
PROC Star

Would it qualify as not using INFILE if the external file had a "datalines;" statement as its first line.  If so, then such a file can be %INCLUDEd (like c:\temp\t.txt below in the second data step.  

 

filename f 'c:\temp\t.txt';
data _null_;
  file f;
  put 'datalines;';
  put '1 1 1';
  put '2 2 2';
run;

data t;
  input a b c;
  %include 'c:\temp\t.txt';
run;

Those who are facile with their operating system commands can probably create a pipe with the "datalines;" statement dynamically inserted before streaming the file in question.  Then just %INCLUDE the pipe.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Kurt_Bremser
Super User

When reading text files, you will always have an INFILE statement, either written by you or by the IMPORT procedure.

 

What's so bad about INFILE? Did it bite you?

Aexor
Lapis Lazuli | Level 10
Thanks 🙂 . I always prefer INFILE .
this question is asked by my colleague though i dont know any other ways except INFILE
so asked for help 🙂

This community is amazing. Thank you all!!

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