SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JJP1
Pyrite | Level 9

Hi All even thogh memid is having name as sasadministartors iam getting incorrect value as vv instead of SAS Administrators if i use nested if not=

syntax,please help

data t;
	set work.groupmempersons_info(where=(memid='xxxxxxxxx'));
	length desc $255;
	call missing (desc);
	if memName = "sasadm" or memname = "sasevs" or memname = "sastrust" then put "Account is sasadm, sasevs or sastrust, skipping.";
else 
if Name= :'SASAdministrators' or Name= :'DI Developers'  then desc='SAS Administrator';
if Name not= :'XXX' and Name not=:'YYY' then desc='vv';
;
		rc=metadata_setattr("omsobj:person\"||memid,"Desc",desc);

                        
    put rc=;
	run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

This statement:

if Name not= :'XXX' and Name not=:'YYY' then desc='vv';

Is always executed regardless of what happened with the earlier if.

I think you want:

data t;
	set work.groupmempersons_info(where=(memid='xxxxxxxxx'));
	length desc $255;
	call missing (desc);
	if memName = "sasadm" or memname = "sasevs" or memname = "sastrust" then put "Account is sasadm, sasevs or sastrust, skipping.";
else /* <= this else only effects the next statement*/
if Name= :'SASAdministrators' or Name= :'DI Developers'  then desc='SAS Administrator';
ELSE if Name not= :'XXX' and Name not=:'YYY' then desc='vv';
;
		rc=metadata_setattr("omsobj:person\"||memid,"Desc",desc);

                        
    put rc=;
	run;

 

View solution in original post

1 REPLY 1
ballardw
Super User

This statement:

if Name not= :'XXX' and Name not=:'YYY' then desc='vv';

Is always executed regardless of what happened with the earlier if.

I think you want:

data t;
	set work.groupmempersons_info(where=(memid='xxxxxxxxx'));
	length desc $255;
	call missing (desc);
	if memName = "sasadm" or memname = "sasevs" or memname = "sastrust" then put "Account is sasadm, sasevs or sastrust, skipping.";
else /* <= this else only effects the next statement*/
if Name= :'SASAdministrators' or Name= :'DI Developers'  then desc='SAS Administrator';
ELSE if Name not= :'XXX' and Name not=:'YYY' then desc='vv';
;
		rc=metadata_setattr("omsobj:person\"||memid,"Desc",desc);

                        
    put rc=;
	run;

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 717 views
  • 0 likes
  • 2 in conversation