Hi Team,
I have a dataset test and in this dataset I have columns like acctn, cust_name, gender, address curr_date. I want to validate all the attributes of this datasets such as account number should always remain numeric and meta data should not change for all the columns. and I want to send an email to the user if the any attribute change for any column.
attributes ie. type of column, length, format, informat, label, all kind.
DATA Test;
infile datalines;
datalines;
12345 ram M POST OFFICE 2013 12/01/2018
43215 sham F POST OFFICE 2014 12/02/2018
45678 geeta M POST OFFICE 2015 12/03/2018
45677 **bleep**a F POST OFFICE 2016 12/04/2018
;
RUN;
A dataset does not change attributes out of the blue, there must be code that does that; fix this code, and you won't have to send any notifications. In particular, NEVER use proc import in production code.
Ok. So what is your question for us to answer?
You would keep the old data and you can access the formats/types/lengths from SASHELP.VCOLUMN or Dictionary.column and then compare them using your own routine or PROC COMPARE. Then if there's a difference, trigger the email. This is a well documented issue with lots of examples online so there should be a lot out there to get you started.
Send emails:
PROC COMPARE:
@abhityagi wrote:
Hi Team,
I have a dataset test and in this dataset I have columns like acctn, cust_name, gender, address curr_date. I want to validate all the attributes of this datasets such as account number should always remain numeric and meta data should not change for all the columns. and I want to send an email to the user if the any attribute change for any column.
attributes ie. type of column, length, format, informat, label, all kind.
DATA Test;
infile datalines;
datalines;
12345 ram M POST OFFICE 2013 12/01/2018
43215 sham F POST OFFICE 2014 12/02/2018
45678 geeta M POST OFFICE 2015 12/03/2018
45677 **bleep**a F POST OFFICE 2016 12/04/2018
;
RUN;
You could try something as below, here I chose the sashelp.class dataset and wanted to check its variable type whether it is character or numeric, if the attribute of the variable is against my expectation then I used the if then condition to send an email.
we need to do at the bigger scale for all the variables you want to test. but hope this code will help you somewhat.
%macro test;
data _null_;
set sashelp.class;
call symput('typ',vtype(name));
run;
%put &typ;
%if &typ ne C %then %do;
filename x email to='xxxx@gmail.com';
data _null_;
file x;
put 'Hi';
run;
%end;
%mend;
%test;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.