Hello friends - I need help on below logic please!!!
I am checking existance of file - if not exist than send email if exist check records and if records r less than certain number then send email...
%let testfile='c:\test.txt';
%macro check;
/*check file and if file exist take it into sas*/
%if %sysfunc(fileexist(&testfile) %then %do;
data work.abc;
infile 'c:\test.txt dlm=',' dsd;
input name $ id number1;
run;
%end;
/*if not exist then abort and send email*/
%else %do;
data _null_;
abort return;
run;
FIlename mymail email "emaild"
subject="sas message"
to="emailid";
data _null_;
file mymail;
put "file not exist";
run;
%end;
/*if exist then use sas dataset created by data step above*/
%else %do;
%let dsid=%sysfunc(open(abc));
%let num=%sysfunc(attrn(&dsid,nobs));
%let rc=%sysfunc(close(&dsid));
%put message;
%if &num<50000 %then %do;
FIlename mymail email "emaild"
subject="sas message"
to="emailid";
data _null_;
file mymail;
put "file has less than 50000 records";
run;
%end;
%else %if &num>50000 %then %do;
data _null_;
put 'enogh records';
run;
%mend;
%check;
/*but I am getting error about imbalance if then else statement*/
thanks!!!
You can do all of that in ONE data step. Lookup FILEVAR option and PUT Statement E-Mail Directives
Message was edited by: data _null_
Please check wether %end statement should be specified before the %mend statement.
You can do all of that in ONE data step. Lookup FILEVAR option and PUT Statement E-Mail Directives
Message was edited by: data _null_
Hi,
Just based on the SAS log messages seen after submitting the macro definition and correcting the first two:
A close bracket is missing here:
%if %sysfunc(fileexist(&testfile)) %then %do;
A close quote is missing here:
infile 'c:\test.txt' dlm=',' dsd;
There is an %else %do that has no matching %if here:
/*if exist then use sas dataset created by data step above*/
%else %do;
Regards,
Amir.
check this if its help - we just had same kind conversation before couple of days...
Hi, Sandy
Although I assume you are using Enterprise Guide, for questions like this you should post them to one of the SAS programming forums; you'll get more SAS programmers looking at them there.
Tom
Hi Tom - can i please have that link? - Thanks!!!
I think i resolve my issue...
i have created two separate macro logic
/*logic1*/
check if file exist and if exist then get into sas using data and infile statement
if not - then abort
/*if logic 1 is right then */
use that dataset created by data and infile statement from above and two separate condition
/*condition 1*/
if records are less than certain number then send email to team
/*condition 2*/
if records are good enough to process then right small message in log only - not sending any email to team.
- Thanks all!!!
It's the same place you posted this. Just go up one level.
Two good ones for people programming in SAS are:
SAS Procedures
SAS Macro Facility, Data Step and SAS Language Elements
Tom
thanks!!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.