BookmarkSubscribeRSS Feed
newbi
SAS Employee
I have following SAS code that looks for "DailySales" files and import daily sales data into SAS data set. What i would like to do is the code to search for the "DailySales" files and if it doesn't find the "DailySales" files then use the "DailyImport" file.

[pre]
Data work.DailySales ;
INFILE "C:\DailySales"
LRECL=143
ENCODING="WLATIN1"
TERMSTR=CRLF
TRUNCOVER ;
.....
[/pre]
10 REPLIES 10
Peter_C
Rhodochrosite | Level 12
the infile option FILEVAR= allows you to define the physical file name at runtime ( so, after you check that the file exists).
The FILEEXIST() function allows your data step to decide which to read
Ksharp
Super User
Hi.Another choice is to use filename + pipe.

[pre]
filename file pipe 'dir C:\DailySales /B';

data temp;
infile file truncover;
input fname $20.;
fname=coalesce(fname,'DailyImport');
......
[/pre]




Ksharp
newbi
SAS Employee
Thanks for all reply. I will try both methods.
Ksharp
Super User
Hi.
Sorry.My code is wrong.
It is my fault that not test it. Please ignore me.


Ksharp
Ksharp
Super User
OK.I will give you a solution.The following code is right. I test it by myself.
[pre]
%let path=c:\;
filename fname pipe "dir &path.dailysales.txt &path.dailyimport.txt /B";
data want;
infile fname truncover;
input fname $20.;
fname="&path"||fname;
infile dummy filevar=fname end=last length=len;
do until( last);
input row $varying200. len;
output;
if last then stop;
end;
run;
[/pre]



Ksharp
newbi
SAS Employee
Ksharp,

I'm using unix and getting error for using pipe:

ERROR: Insufficient authorization to access PIPE.

%let path="/mnt/data/";
filename fname pipe "/mnt/data/ &path.dailysales.txt &path.dailyimport.txt /B";
RMP
SAS Employee RMP
SAS Employee
There could be a number of reasons. From where are you running this code? Base SAS, EGuide?

If you are running it from Eguide, it may be that the object spawner is not allowed to execute external OS commands. You will need to add a NONOXCMD to the object spawner startup command.

Just looked again at your code. What exactly are you trying to do in the PIPE statement? You are missing the DIR in the filename statement.

Message was edited by: RMP Message was edited by: RMP
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest the OP search the SAS support website for additional info.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

ERROR: Insufficient authorization to access PIPE site:sas.com
Ksharp
Super User
Under Unix, you should use ' ls ' command to check the list of directory.
But from your log, it is to say you do not have right to use PIPE functionality.
If you can ,contact with SAS Administrator, to see whether to open it for you.
If you can not ,can refer to the SAS code which used fopen() function written by SASKiWi at previous post.

Ksharp
Ksharp
Super User
Or you can code like this.But need to change the path into unix (/mnt/data/trans.txt)


[pre]
filename a 'c:\trans.txt';

%let a=%sysfunc(fexist(a) );

%macro imp;
%if &a=1 %then %do;
proc import datafile='c:\trans.txt' out=want dbms=tab replace;
getnames=yes;
run;
%end;
%else %do;
proc import datafile='c:\dailysales.txt' out=want dbms=tab replace;
getnames=yes;
run;
%end;
%mend imp;

%imp
[/pre]


Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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