I have a list of 15 similar variables that I want to loop through syntax to recode as null. I will be adding more variables to this list so that's why I went with a macro. I created a macro variable that stores a list of variables and another macro variable that stores the count of variables. I am having trouble defining the array. I got the code below to work, but it only goes through varlist1, and not the other 14 variables (varlist2-varlist15)... which is what I told it to do but I can't figure out how to expand it to the full list of variables without breaking the code. I searched through the forums and SAS articles but couldn't find an answer. I'm fairly new to arrays so I'm sure it's something simple I don't understand. appreciate any help and let me know if I can post better next time. first one. :)
this is my list in &varlist.
(
NEW_CREWSTATE1A
NEW_EquFailText
NEW_ExpMedNotList
NEW_NARRATIVEDISTRESS
NEW_NarrativeRecovery
NEW_NarrativeSearch
NEW_OthEquText
NEW_PersReqMedTxt
NEW_ProbEnct
NEW_Recommend
NEW_RescueSwimProbText
NEW_RescuerProb
NEW_SRUConfigTxt
NEW_equimalissue
new_MedDiffText
)
code:
proc sql noprint;
select count(name) into :numVar
from sashelp.vcolumn
where upcase(LIBname)="STAGING" and UPCASE(memname)="RESC_NARRATIVEMERGE" and UPCASE(name) like 'NEW_%';
quit;
%put &numVar;
proc sql noprint;
select distinct(name) into :varlist1-
from sashelp.vcolumn
where upcase(LIBname)="STAGING" and UPCASE(memname)="RESC_NARRATIVEMERGE" and UPCASE(name) like 'NEW_%';
quit;
data staging.RESC_NARRATIVEMERGE2;
set staging.RESC_NARRATIVEMERGE;
array narrative_array {*} &varlist1. ;
do i=1 to dim(narrative_array);
if strip(narrative_array{i})='N/A' then narrative_array{i}='';
if strip(narrative_array{i})='N/A.' then narrative_array{i}='';
if strip(narrative_array{i})='NA' then narrative_array{i}='';
if strip(narrative_array{i})='NONE' then narrative_array{i}='';
if strip(narrative_array{i})='NONE NOTED' then narrative_array{i}='';
if strip(narrative_array{i})='NONE EXPERIENCED' then narrative_array{i}='';
if strip(narrative_array{i})='NONE TO REPORT' then narrative_array{i}='';
if strip(narrative_array{i})='NONE.' then narrative_array{i}='';
if strip(narrative_array{i})='NOT APPLICABLE' then narrative_array{i}='';
end;
run;