Help using Base SAS procedures

Check for table before attempting to process.

Reply
New Contributor
Posts: 2

Check for table before attempting to process.

Hi, I'm new to SAS and am having a hard time figuring out something that I would think would be simple.

I've searched the web, found several different versions but I can't seem to get any of them to work.

The Problem:

We have another system that generates a table around the 15th of each month. Once the table is created we can create our data based on that table. I've searched the internet and found multiple variations of what I want, but I can't seem to make any of them work.

It's a pain to have to check for the table all the time and I would like to automate the process.

What I need to find is a macro that will check to see if the table exists,

If it's not there exit the whole process.

If it is there, run the rest of the code and generate our data.

in simple terms:

if exists(mytable) = false then abort and close else continue running the code

 

I do have a background in other programming languages and SQL, but SAS just continues to baffle me. Smiley Happy

 

Using:

SAS EG: 7.100.0.1966

SAS Version: 9.4.3.0

Super User
Posts: 18,603

Re: Check for table before attempting to process.

[ Edited ]

See the example here:

http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1hogk0ekd1z62n18...

 

This macro verifies that an external file exists. If it does not exist, then a message is written to the log. If the file does exist, then the file is opened and SAS attempts to read the data within the file. Functions, such as FOPEN, FREAD and FGET, are used to retrieve the data. If there is no data to be read, a message is written to the log that the file is empty.

 


Erik_2017 wrote:

Hi, I'm new to SAS and am having a hard time figuring out something that I would think would be simple.

I've searched the web, found several different versions but I can't seem to get any of them to work.

The Problem:

We have another system that generates a table around the 15th of each month. Once the table is created we can create our data based on that table. I've searched the internet and found multiple variations of what I want, but I can't seem to make any of them work.

It's a pain to have to check for the table all the time and I would like to automate the process.

What I need to find is a macro that will check to see if the table exists,

If it's not there exit the whole process.

If it is there, run the rest of the code and generate our data.

in simple terms:

if exists(mytable) = false then abort and close else continue running the code

 

I do have a background in other programming languages and SQL, but SAS just continues to baffle me. Smiley Happy

 

Using:

SAS EG: 7.100.0.1966

SAS Version: 9.4.3.0


 

Super User
Posts: 10,890

Re: Check for table before attempting to process.

Is the "table" an external file, a table in a DBMS or is it a SAS data set? Different approaches are likely needed depending on what environment you are working in.

 

For instance the SAS function EXIST (not exists) is used to confirm the existence of as SAS data set.

 

The function FEXIST verifies the existence of an external file such as  "C:\path\file.txt"

 

If the table exists in an anothe DBMS such as Oracle or SQL Server then you'll likely have additional steps involved to connect to the DBMS and query.

 

 

New Contributor
Posts: 2

Re: Check for table before attempting to process.

Thank you for the quick responses.

Reeza, I will try your suggestion, It looks like more than I need, but if I can get it working I can probably cut it down . Thanks

 

BallardW, Lesson learned Smiley Happy Need to be more specific, hehe.

The "table" is a SAS dataset that gets created by another group. I am using EG to build my programs on a windows pc. The server is running on a *nix box somewhere else. Eventually I will copy the .SAS file from the EGP to the server and set up a CRON job.

 

Thank you for you time.

 

Ask a Question
Discussion stats
  • 3 replies
  • 129 views
  • 2 likes
  • 3 in conversation