DATA Step, Macro, Functions and more

Exist function not detecting the dataset in SAS Batch run

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Exist function not detecting the dataset in SAS Batch run

Hi All,

 

I have the following shell script to run the job.

 

cd ${PROJ_ENV}/data/batchout

. ${PROJ_ENV}/data/batchout/exec_sas_di.sh STP_Report_TEST1 &

. ${PROJ_ENV}/data/batchout/exec_sas_di.sh STP_Report_TEST2 &

 

In the first program, I am creating a dataset(DOC_TAB) in SASTAB library.(SASTAB.DOC_TAB).

 

In the second program, when I am checking whether dataset is exist or not using EXIST fn( tried both EXIST or OPEN function), it always returns FALSE during very first run of the job.

 

From the second run onwards, this checking of dataset returns TRUE.

 

Please let me know why the second program is not detecting the dataset(Permanent dataset) created in first program.

 

Thanks in advance.

 

Thanks,
Sampath

 

 

 


Accepted Solutions
Solution
‎02-28-2017 08:45 AM
Super User
Posts: 7,774

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to bmsampath

bmsampath wrote:

I dont have much knowledge in UNIX. I accept whatever you are saying is correct. Could you please tell me how to run the code one by one to avoid this issue ..First TEST1 then TEST2.

 

Can you give some details abt how to change the unix shell script?

 

Thanks,Sampath


Just remove the ampersands. Then the script has to wait for the first program to finish before it can start the second.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 19,789

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to bmsampath

You need to post some code. 

 

To debug try accessing data in first program and see the error message. It may give you more clues. 

Contributor
Posts: 32

Re: Exist function not detecting the dataset in SAS Batch run

If I check the dataset in first program, exist returns TRUE. But in second program, exist function returns FALSE. This happens only in batch mode. that too during the first run of the job in all dev, si and prod environment. THIS IS PERMANENT DATASET STORED IN A LIBRARY. Still if you want some more details , I am ready to give .
Super User
Posts: 7,774

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to bmsampath

bmsampath wrote:
If I check the dataset in first program, exist returns TRUE. But in second program, exist function returns FALSE. This happens only in batch mode. that too during the first run of the job in all dev, si and prod environment. THIS IS PERMANENT DATASET STORED IN A LIBRARY. Still if you want some more details , I am ready to give .

You are not consistent. From your post:

--

In the first program, I am creating a dataset(DOC_TAB) in SASTAB library.(SASTAB.DOC_TAB).

 

In the second program, when I am checking whether dataset is exist or not using EXIST fn( tried both EXIST or OPEN function), it always returns FALSE during very first run of the job.

--

 

So you were NOT checking for the dataset in your first program, you were CREATING it. Since both programs run in parallel, the second program can't detect the dataset until the script has run at least once.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 32

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to KurtBremser

I tried to check the dataset in first program just for debugging purpose.

 

Actually I am doing the checking in the second program only.

 

First program creates dataset. Second program is checking the dataset and doing something if it is true.

Super User
Posts: 7,774

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to bmsampath

Very simple. By using the ampersand at the end of a command, you let that run in the background, and control is immediately handed back to the script, which starts the second command; so both SAS programs run concurrently, and the second program starts before the first program had a chance to write the dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 32

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to KurtBremser

I dont have much knowledge in UNIX. I accept whatever you are saying is correct. Could you please tell me how to run the code one by one to avoid this issue ..First TEST1 then TEST2.

 

Can you give some details abt how to change the unix shell script?

 

Thanks,Sampath

Solution
‎02-28-2017 08:45 AM
Super User
Posts: 7,774

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to bmsampath

bmsampath wrote:

I dont have much knowledge in UNIX. I accept whatever you are saying is correct. Could you please tell me how to run the code one by one to avoid this issue ..First TEST1 then TEST2.

 

Can you give some details abt how to change the unix shell script?

 

Thanks,Sampath


Just remove the ampersands. Then the script has to wait for the first program to finish before it can start the second.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 32

Re: Exist function not detecting the dataset in SAS Batch run

Posted in reply to KurtBremser

Big Thanks. Now it is working after removing amphersand. Thanks,Sampath

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 139 views
  • 0 likes
  • 3 in conversation