BookmarkSubscribeRSS Feed
noda6003
Quartz | Level 8

I have one library of 39 datasets and one single dataset with all variable names and labels and i want to see if the single dataset with all variable names and datasets have the same name and label in all datasets combined. i.e i want to compare if they are any mismatches between my mother file which has all var names and labels are present in all datasets.

 

Any help on how to do this in sas

3 REPLIES 3
andreas_lds
Jade | Level 19
You can find the names and labels of all datasets in sashelp.vcolumn => extract the relevant information from that dataset and use proc compare with your "mother file".
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @noda6003 

 

I found some code which I think does what you want. It reports any variables not found in reference together with variables with different attributes. It does not report missing variables compared to reference, because in my case not all data sets are expected to contain all variables.

 

Any differences are shown as the attribute value followed by the atrtribute value from the reference data set in parentheses.

 

Note also that my code expects reference data set to be in the same library, but it only a minor correction to the code to change that. I had to make som test data, because I didn't have a real example with all types of differences.

 

Test data 

 

libname mylib 'c:\temp\testlib';
data mylib.dictionary;
	attrib id length=8 label='Identity';
	attrib name length=$34 label='Person Full name';
	attrib amount length=8 format=commax12.0;
	attrib qt length=8 label='Quantity'	;
run; 
data mylib.a;
	attrib id length=8 length=5;
	attrib name length=$34 label='PersonName';
	attrib sales_amount length=8 format=commax12.0;
run; 
data mylib.b;
	attrib ID length=$8 label='Identity';
	attrib name length=$40 label='Person Full name';
	attrib amount length=8 format=12.0;
	attrib qt length=5 label='Quantity Sold';
	;
run; 

program to report differences:

 

/***************************************************************************/
/* Report variables in library not found in reference or with different    */
/*      attributes (varname upper/lowercase, label, type, length, format)  */
/* Missing variables compared to reference are not included                */
/* If attributes are different, the attribute is shown together with the   */
/*      atrtribute from reference in parentheses.                          */
/***************************************************************************/

%let mydict = dictionary;
%let mypath = c:\temp\testlib;

proc sql;
	create table diff as
		select 
			a.memname, 
			a.name, 
			a.label, 
			a.type, 
			a.length, 
			a.format,
			b.name as refname,
			b.label as reflabel,
			b.type as reftype,
			b.length as reflength,
			b.format as refformat
		from (
			select memname, name, label, type, length, format
			from sashelp.vcolumn
			where libname = 'MYLIB' and memname ne upcase("&mydict")
		) as a
		left join (
			select memname, name, label, type, length, format
			from sashelp.vcolumn
			where libname = 'MYLIB' and memname = upcase("&mydict")
		) as b
		on upcase(a.name) = upcase(b.name) 
		where 
			a.name ne b.name or 
			a.label ne b.label or 
			a.type ne b.type or 
			a.length ne b.length or 
			a.format ne b.format
		order by memname, name;
quit; 

data report; set diff;
	length Dataset $32 VarName $65 VarLabel $256 VarType $13 VarLength $13 VarFormat $67;
	keep Dataset VarName VarLabel VarType VarLength VarFormat;
	Dataset = memname;
	if refname = '' then do;
		VarName = trim(name) || ' (Variable not in Ref.)';
		VarLabel = '-';
		VarType = '-';
		VarLength = '-';
		VarFormat = '-';
	end;
	else do;
		if name ne refname then 
			VarName = trim(name) || ' (' || trim(refname) || ')';
		else VarName = name;

		if label = '' and reflabel ne '' then 
			VarLabel = '-none- (' || trim(reflabel) || ')';
		else if label ne '' and reflabel = '' then 
			VarLabel = trim(label) || ' (-none-)';
		else if label ne reflabel then 
			VarLabel = trim(label) || ' (' || trim(reflabel) || ')';

		if type ne reftype then 
			VarType = trim(type) || ' ('||trim(reftype) || ')';
		if length ne reflength then 
			VarLength = strip(put(length,8.)) || ' (' || strip(put(reflength,8.)) || ')';

		if format = '' and refformat ne '' then 
			VarFormat = '-none- (' || trim(refformat) || ')';
		else if format ne '' and refformat = '' then 
			VarFormat = trim(format) || ' (-none-)';
		else if format ne refformat then 
			VarFormat = trim(format) || ' (' || trim(refformat) || ')';
	end;
run;

proc print data=report noobs;
run;

Output:

 

 

varcomp.gif

 

 

ballardw
Super User

My approach is code similar to:

Proc tabulate data=sashelp.vcolumn;
   where LIBNAME='YOURLIB';
   class memname name label;
   tables name*label,
          memname*n=''
/misstext=' ' ; run;

LIBNAME is the library of interest, put yours in upper case as that is how they are stored.

Memname is the data set name, Name is the variable name and Label is the variable label.

The code will place the memnames as column headings and the variables in rows (assumes you have more variables than data sets, change the order of name*label and memname in the tables statement if not the case).

There will be 1 (one digit) in the cells intersecting the column and row.

Nesting the Name and Label will show if the same variable has different labels in different data sets.

 

Here is an example output (partial) using the listing destination: The funny characters are replacing the SAS MONOSPACE Font box drawing characters because the forum doesn't support them.

„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†
‚                      ‚                          Member Name                           ‚
‚                      ‡ƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚                      ‚  FPCHECK   ‚  HIVCHECK  ‚HIV_FORMATS ‚ XPEMS2008  ‚ XPEMS2009  ‚
‡ƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚Column    ‚Column     ‚            ‚            ‚            ‚            ‚            ‚
‚Name      ‚Label      ‚            ‚            ‚            ‚            ‚            ‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒ‰            ‚            ‚            ‚            ‚            ‚
‚AgencyID  ‚Agency ID  ‚            ‚            ‚            ‚            ‚            ‚
‚          ‚code       ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚AgencyIDT-‚Agency     ‚            ‚            ‚            ‚            ‚            ‚
‚ext       ‚           ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚BirthSex  ‚Birth Sex  ‚            ‚            ‚            ‚            ‚            ‚
‚          ‚code       ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚CBO_Agenc-‚CBO Agency ‚            ‚            ‚            ‚            ‚            ‚
‚y_ID      ‚ID         ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚CDC01     ‚CDC        ‚            ‚            ‚            ‚            ‚            ‚
‚          ‚variable 1 ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚CREATED_ON‚Date record‚            ‚            ‚            ‚            ‚            ‚
‚          ‚created    ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚ClientId  ‚Client ID  ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚ClientIdC-‚Client ID  ‚            ‚            ‚            ‚            ‚            ‚
‚har       ‚non-numeric‚            ‚            ‚            ‚            ‚            ‚
‚          ‚characters ‚           1‚            ‚            ‚            ‚            ‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚ClientIdF-‚Client ID  ‚            ‚            ‚            ‚            ‚            ‚
‚ail       ‚problem    ‚           1‚            ‚            ‚            ‚            ‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚ClientIdM-‚Client ID  ‚            ‚            ‚            ‚            ‚            ‚
‚iss       ‚Missing    ‚           1‚            ‚            ‚            ‚            ‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚Client_Pa-‚Client     ‚            ‚            ‚            ‚            ‚            ‚
‚rtner_Ser-‚Partner    ‚            ‚            ‚            ‚            ‚            ‚
‚vices_30d-‚Services   ‚            ‚            ‚            ‚            ‚            ‚
‚ays       ‚Interview  ‚            ‚            ‚            ‚            ‚            ‚
‚          ‚within 30  ‚            ‚            ‚            ‚            ‚            ‚
‚          ‚days of HIV‚            ‚            ‚            ‚            ‚            ‚
‚          ‚Result     ‚            ‚            ‚            ‚           1‚           1‚
‡ƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚Client_Pa-‚Client     ‚            ‚            ‚            ‚            ‚            ‚
‚rtner_Ser-‚Partner    ‚            ‚            ‚            ‚            ‚            ‚
‚vices_Int-‚Services   ‚            ‚            ‚            ‚            ‚            ‚
‚ervie     ‚Interview  ‚            ‚            ‚            ‚           1‚           1‚
Šƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒŒ


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 959 views
  • 2 likes
  • 4 in conversation