BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

 

I would like to add a prefix text, 'SEC_', to the ARRAY variable columns as my code shown below.  I got an error message from the log window.  Please help me to fix it.  Thanks.

 

data Want;
	set Have;
	
	array vars uairway uapnea ugastro ugerd uendo uallergy uprem unone;
    do over vars;
        if find(SEC_uothersp_update1,vname(vars),"i") then 'SEC_'||vars=1;
    end;
	
	
run;

Log massage shows:

 

do over vars;

 if find(SEC_uothersp_update1,vname(vars),"i") then 'SEC_'||vars=1;

                                                                                      ------

                                                                                      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

 end;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @ybz12003  Array variables are created at compile time and not at execution time. Therefore, your idea wouldn't work. However you could create another array statement defining its variable with SEC prefix like the below-

 


data Want;
	set Have;
	
	array vars uairway uapnea ugastro ugerd uendo uallergy uprem unone;
	array s  sec_uairway sec_uapnea sec_ugerd sec_uendo sec_uallergy sec_uprem sec_unone;
    do over vars;
        if find(SEC_uothersp_update1,vname(vars),"i") then s=1;
    end;
	
	
run;

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @ybz12003  Array variables are created at compile time and not at execution time. Therefore, your idea wouldn't work. However you could create another array statement defining its variable with SEC prefix like the below-

 


data Want;
	set Have;
	
	array vars uairway uapnea ugastro ugerd uendo uallergy uprem unone;
	array s  sec_uairway sec_uapnea sec_ugerd sec_uendo sec_uallergy sec_uprem sec_unone;
    do over vars;
        if find(SEC_uothersp_update1,vname(vars),"i") then s=1;
    end;
	
	
run;

 

ybz12003
Rhodochrosite | Level 12
Thanks much!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 805 views
  • 1 like
  • 2 in conversation