- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!!!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can do all of that in ONE data step. Lookup FILEVAR option and PUT Statement E-Mail Directives
%let obs=5000;
data _null_;
length message $128 filevar $256 to $64;
to = 'you@yourhouse.com';
filevar = pathname('FT16F001','F');
rc = fileexist(filevar);
if rc eq 0 then do;
Message = 'File does not exist';
link email;
end;
else do;
infile dummy1 filevar=filevar eof=eof firstobs=&obs;
input;
message = "File has at least &obs records";
link email;
eof:
message = "File has less than &obs records";
link email;
end;
email:
file dummy2 email filevar=to;
put '!em_subject! ' filevar=;
put message=;
put filevar=;
stop;
run;
filename FT16F001 clear;
Message was edited by: data _null_
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please check wether %end statement should be specified before the %mend statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can do all of that in ONE data step. Lookup FILEVAR option and PUT Statement E-Mail Directives
%let obs=5000;
data _null_;
length message $128 filevar $256 to $64;
to = 'you@yourhouse.com';
filevar = pathname('FT16F001','F');
rc = fileexist(filevar);
if rc eq 0 then do;
Message = 'File does not exist';
link email;
end;
else do;
infile dummy1 filevar=filevar eof=eof firstobs=&obs;
input;
message = "File has at least &obs records";
link email;
eof:
message = "File has less than &obs records";
link email;
end;
email:
file dummy2 email filevar=to;
put '!em_subject! ' filevar=;
put message=;
put filevar=;
stop;
run;
filename FT16F001 clear;
Message was edited by: data _null_
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
check this if its help - we just had same kind conversation before couple of days...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thanks!!!