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';
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.