Hi All
Please help me. I need a program to check the variables in a dataset and if possible list the variable type.
Example: I have 3 datasets. I need to check the variables in each dataset at the end of the month in order to track changes to the dataset structure and raise a flag if the table structure changes.
Test201207 has 2 variables: amount, date
Test201208 has 3 variables: amount, date and customer_id
Test201209 has 4 variables: amount, date, customer_id and count
Thanks
I think if you make a grid with memnames down the side and variable names across and put type in the cells you can find all the answers you need with one simple report.
data
test201207(keep=amount date)
test201208(keep=amount cdate customer_id rename=(cdate=date))
test201209(keep=amount date customer_id count)
;
attrib amount length=8;
attrib date length=8;
attrib cdate length=$10;
attrib customer_id length=$10;
attrib count length=8;
stop;
call missing(of _all_);
run;
proc contents data=work._all_ noprint
out=contents(keep=memname name type where=(memname eq: 'TEST'));
run;
proc print;
run;
proc transpose out=report(drop=_name_ _label_);
by memname;
var type;
id name;
run;
proc print;
run;
customer_
Obs MEMNAME amount date id count
1 TEST201207 1 1 . .
2 TEST201208 1 2 2 .
3 TEST201209 1 1 2 1
is this what you want:
proc contents data=sashelp.class out=class(keep=name type) noprint;
run;
proc print data=class;run;
Obs NAME TYPE
1 Age 1
2 Height 1
3 Name 2
4 Sex 2
5 Weight 1
Thanks for your response Linlin.
Yes but I need to see how it differs from the previous datasets - what new variable has been added.
How about:
data class1 class2;
set sashelp.class;
data class1;
set class1;
room=3;
data class2;
set class2;
grade='a';
proc contents data=class1 out=class_1(keep=name type) noprint;
proc contents data=class2 out=class_2(keep=name type) noprint;
run;
proc sort data=class_1;
by name;
proc sort data=class_2;
by name;
run;
data check;
length status $ 18;
merge class_1(in=a) class_2(in=b);
by name;
if a and b then status='both';
else if a and not b then status='class_1 only';
else status='class_2 only';
proc print;run;
Obs status NAME TYPE
1 both Age 1
2 both Height 1
3 both Name 2
4 both Sex 2
5 both Weight 1
6 class_2 only grade 2
7 class_1 only room 1
Check out the tables in the DICTIONARY library. They make it very easy to get dataset characteristics in a machine readable form. Setting up a scheme to retain the old settings, and compare them with the new ones, should be very easy. PROC COMPARE might do the job nicely.
Tom
I think if you make a grid with memnames down the side and variable names across and put type in the cells you can find all the answers you need with one simple report.
data
test201207(keep=amount date)
test201208(keep=amount cdate customer_id rename=(cdate=date))
test201209(keep=amount date customer_id count)
;
attrib amount length=8;
attrib date length=8;
attrib cdate length=$10;
attrib customer_id length=$10;
attrib count length=8;
stop;
call missing(of _all_);
run;
proc contents data=work._all_ noprint
out=contents(keep=memname name type where=(memname eq: 'TEST'));
run;
proc print;
run;
proc transpose out=report(drop=_name_ _label_);
by memname;
var type;
id name;
run;
proc print;
run;
customer_
Obs MEMNAME amount date id count
1 TEST201207 1 1 . .
2 TEST201208 1 2 2 .
3 TEST201209 1 1 2 1
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.