I have a SAS table with columns of dataset name and field names. I need to take the dataset name, and field name in each row and test if the dataset exists under a directory; if exists, I need to test if the field exists in the dataset. Then I need to update the table with two additional columns DatasetExit and FieldExist with 'Yes' and 'No'.
Any suggestions would be highly apprecaited!
Something like this perhaps?
data have;
informat memname name $32.;
input memname name;
label memname='Data set name'
name ='Variable name'
;
datalines;
class sex
class name
class town
iris species
iris petalwidth
iris weight
frivolous name
;
run;
proc sql;
create table want as
select a.*, exist(cats("SASHELP.",a.memname),'DATA') as DataSetExists,
(not missing(b.name) ) as FieldExist
from have as a left join ( select * from dictionary.columns where libname='SASHELP') as b on
upcase(a.memname)=upcase(b.memname) and upcase (a.name)=upcase(b.name);
quit;
This has 1 for yes and 0 for no. You can assign a format or add logic. I recommend a format.
Hi Ballardw, I appreciate your detailed solution! I will try implement it and let you know how it works.
Thanks, Zhuo
Hi Ballardw,
I have a chance and implemented the solution. It worked perfectly! You are awesome!
Zhuo
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.