BookmarkSubscribeRSS Feed
sandeep_reddy
Quartz | Level 8

Hi There,

I need to delete externalidentifier of all users which are in SAS Metadata mentioned in MDUCHGVERRORS table.

After that i need to update externalidentifiers of all users which are in MDUCHGVERRORS to SAS Metadata of users.

Manually updating for 500 users is a hectic task and i tried to skip the comparison between AD and Metadata but not helping.

Best Regards,
Sandeep

1 REPLY 1
gwootton
SAS Super FREQ

Assuming you have a table of users and their desired Identifier values (here I'm creating the table work.users manually), you could do something like this:

 

/* Create a data set of users and their desired external identity values. */
data work.users;
length user identifier $ 255;
input user $ identifier $;
datalines;
sasadm 12345
sasdemo 67890
;;
run;

/* DATA step to update these objects. */
data _null_;
	/* Initialize some variables. */
	length type id $ 50 uri extid $ 255;
	call missing(type,id,uri,extid);
	/* Read in the source data set. */
	set work.users;
	/* Define a query to find the ExternalIdentity object associated with that user. */
	obj="omsobj:ExternalIdentity?ExternalIdentity[OwningObject/Person[@Name='"||trim(user)||"']]";
	rc=metadata_resolve(obj,type,id);
	/* If one (and only one) is found... */
	if rc = 1 then do;
		put "NOTE: Found 1 external identity for user " user ;
		/* Get the URI for the object. */
		rc=metadata_getnobj(obj,1,uri);
		/* Pull the existing identifier value. */
		rc=metadata_getattr(uri,"Identifier",extid);
		/* Only take action if the existing value does not match the desired value. */
		if extid ne identifier then do;
			put "NOTE: Identifier does not match table." extid= identifier=;
			put "NOTE- Setting attribute to value in table.";
			/* I've commented out the line that writes to metadata and replaced it with rc=0 to simulate a successful write. */
			/* To activate this code, uncomment the metadata_setattr function and comment out the rc=0. */
			*rc=metadata_setattr(uri,"Identifier",identifier); rc=0;
			if rc=0 then put "NOTE: Attribute updated successfully";
			else put "ERROR: Failed to update attribute for user " user rc=;
		end;
		else put "NOTE: No action needed, external id already matches desired value. " extid= identifier=;
	end;
	else put "NOTE: Taking no action. Found " rc "external identities for user " user;
run;
--
Greg Wootton | Principal Systems Technical Support Engineer

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 155 views
  • 1 like
  • 2 in conversation