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
See the example here:
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
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.
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.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: