I am trying to use an array to clean my data, I have tried a few different things and nothing seems to really change what I am seeing, either in the data or the log.
array optionschar {4} $ gender
Marital_Status
Game_Attendance
games_attended;
do i = 1 to 10;
if optionschar{i} = "Male" then optionschar{i} = "M";
if optionschar{i} = "m" then optionschar{i} = "M";
if optionschar{i} = "Female" then optionschar{i} = "F";
if optionschar{i} = "Mar" then optionschar{i} = "M";
if optionschar{i} = "Married" then optionschar{i} = "M";
if optionschar{i} = "Single" then optionschar{i} = "S";
if optionschar{i} = "999" then optionschar{i} = ".";
if optionschar{i} = "Four" then optionschar{i} = "4";
end;
drop i;
keep gender Marital_Status Game_Attendance games_attended;
run;
why are you looping 10 times when there are only 4 elements in your array. Shouldnt it be
do i=1 to 4;
why are you looping 10 times when there are only 4 elements in your array. Shouldnt it be
do i=1 to 4;
This doesn't even seem like a situation where arrays are useful.
You are performing different tasks on each variable in the array. Arrays are useful when you are performing the same task on each variable in the array.
use proc format and put function
Thank you both for the insight.
Check multiple conditions at once using IN instead of the multiple IF statements:
if optionschar{i} = "Male" then optionschar{i} = "M";
if optionschar{i} = "m" then optionschar{i} = "M"
is the same as:
if optionschar{i} in ("Male", 'm') then optionschar{i} = "M";
And another suggestion, make everything upper case in your comparison to avoid having to check for m, M, Male and male.
if upcase(gender) in ('M', 'MALE') then gender='M';
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: