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

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;        
        
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

why are you looping 10 times when there are only 4 elements in your array. Shouldnt it be 

do i=1 to 4;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

why are you looping 10 times when there are only 4 elements in your array. Shouldnt it be 

do i=1 to 4;

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
novinosrin
Tourmaline | Level 20

use proc format and put function

Andrew6
Calcite | Level 5

Thank you both for the insight.

Reeza
Super User

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';

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 3222 views
  • 6 likes
  • 4 in conversation