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!!

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