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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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