BookmarkSubscribeRSS Feed
RAVI2000
Lapis Lazuli | Level 10

 

I am having multiple study folders which again have multiple folders for rawdata. In them, are my .sas files to input the rawdata. The .sas files have infile statement that includes \ (back slash) and while I am running them I get error since I am running them on unix environment. The macro should also convert the \ to / in the infile statement.

 

Project1

        ---->rawdata

             ---->dm

                       ----> dm.csv (rawdata)

                       ---->dm.sas (is including the dm.csv rawdata file and creating the formats in

              ---->ae

                       ----> ae.csv (rawdata)

                       ---->ae.sas (is including the ae.csv rawdata file and creating the formats in .sas file)

               --->cm

                       --->cm.csv (rawdata)

                       --->cm.sas (is including the cm.csv rawdata and creating the formats in .sas file)

                 --->ex

                                 similar

                                   .

                                   .

                                   .

The sample dm.sas file to read the .csv file

data work.DEMOGRAPHICS frmts.DEMOGRAPHICS;
  %let _EFIERR_ = 0;
  infile '.\Demographics.txt' delimiter='09'x MISSOVER DSD lrecl=32767 firstobs=2 termstr=CRLF;
 INPUT SEQUENCE_NO  BIRTH_DATE AGE_ON_STUDY GENDER RACE ETHNICITY ELIGIBILITY_STATUS ON_STUDY_DATE ARMS;
if _ERROR_ then call symput('_EFIERR_',1);
run;

data DEMOGRAPHICS_FMT;
  set DEMOGRAPHICS;
run;
title "Demographics";

I have these .sas files for all .csv files for multiple projects.

Project2

             ---->rawdata

                          ---->ae

                                  ----> ae.csv (rawdata)

                                  ---->ae.sas (is including the ae.csv rawdata file and creating the formats in .sas file)

                          --->cm

                                  --->cm.csv (rawdata)

                                  --->cm.sas (is including the cm.csv rawdata and creating the formats in .sas file)

                          --->ex

                                 similar

                                   .

                                   .

                                   .

I want to run all the .sas files in batch mode to get the raw datasets.

 

I have did the below to convert the \ to /, but for just one single .sas file. How do I do for all .sas file?

filename fixed '/Studies/Project1/rawdata/AE.sas';
data _null_;
  infile fixed;
  file fixed ;
  input;
  if left(upcase(_infile_))=:'INFILE' then _infile_=translate(_infile_,'/','\');
  put _infile_;
run;

How can I run all .sas file with multiple project folders?

Please let me know if you need any additional information.

PS: I am using SAS on UNIX, and all these projects are in a shared folder drive "z".

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

So you want to:

 1. Gather the list of files to modify

 2. Alter the code to change \ to / 

?

Is that enough? Are the paths really otherwise identical?

For 1.  See the pinned topic "How to: List all the files in a folder "

For 2.  Your code looks fine. You could call it using call execute while reading the list of files fetched in 1.

 

Comment: This could be avoided if paths were not hard-coded in programs, but were stored centrally.

A basic way to do this is keep them in a set of programs and store them in pre-defined macro variables or FILENAMEs or LIBNAMEs.

 

RAVI2000
Lapis Lazuli | Level 10
NOTE: Libref SJ was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: /data/Trials
2          data sj.filenames;
3          length fref $8 fname $200;
4          did = filename(fref,'/data/Trials/ae.sas');
5          did = dopen(fref);
6          do i = 1 to dnum(did);
7            fname = dread(did,i);
8            output;
9          end;
10         did = dclose(did);
11         did = filename(fref);
12         keep fname;
13         run;

NOTE: Argument 1 to function DNUM(0) at line 6 column 13 is invalid.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, 
       or invalid.
fref=#LN00006 fname=  did=0 i=1 _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to 
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 6:13   
NOTE: The SAS System stopped processing this step because of errors.
NOTE: Due to ERROR(s) above, SAS set option OBS=0, enabling syntax check mode. 
      This prevents execution of subsequent data modification statements.
WARNING: The data set SJ.FILENAMES may be incomplete.  When this step was stopped there were 0 observations and 1 variables.
WARNING: Data set SJ.FILENAMES was not replaced because this step was stopped.

I am running SAS on UNIX envi. Please look into the log and let me know where I am going wrong.

Thanks

RAVI2000
Lapis Lazuli | Level 10
Sorry Kurt. I didn't quite catch you. I am trying everything and not a solution i am getting. It keep on says the directory doesn't exist. I am now exhausted!!!
Tom
Super User Tom
Super User

Use the directory name, not the name of any individual file in the directory.

1    filename xx '/unkown/directory';
2    data _null_;
3      did=dopen('xx');
4      put did=;
5      message=sysmsg();
6      put message=;
7      if did then did=dclose(did);
8    run;

did=0
message=ERROR: Physical file does not exist, /unkown/directory.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

If the directory does not exist then it does not exist.  

Are you sure the path you are using is the right path for the server where the SAS code is running?

 

Kurt_Bremser
Super User

@RAVI2000 wrote:
Sorry Kurt. I didn't quite catch you. I am trying everything and not a solution i am getting. It keep on says the directory doesn't exist. I am now exhausted!!!

Something with a .sas extension is usually a SAS program (a text file containing SAS code), just like an object with a .csv extension is a data file (comma-separated text). Files can not be accessed with the DOPEN function, only directories.

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
  • 6 replies
  • 908 views
  • 1 like
  • 4 in conversation