BookmarkSubscribeRSS Feed
Erik_2017
Calcite | Level 5

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. 🙂

 

Using:

SAS EG: 7.100.0.1966

SAS Version: 9.4.3.0

3 REPLIES 3
Reeza
Super User

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. 🙂

 

Using:

SAS EG: 7.100.0.1966

SAS Version: 9.4.3.0


 

ballardw
Super User

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.

 

 

Erik_2017
Calcite | Level 5

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 🙂 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.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1320 views
  • 2 likes
  • 3 in conversation