BookmarkSubscribeRSS Feed
a_ramos
Obsidian | Level 7

Is it possible to create an array with string values (not variables) to rename values?

I know a macro does this, but it's already inside a parent macro.

 

I know that this query does not work, but it would be something like this:

DATA ONE;
SET TWO;

ARRAY REWRITE{2, 5} "LilyOrchid" "LilyRose" "LilyRoseOrchid" "LilyRoseJasmine" "LilyRoseOrchidJasmine" "2FOrchid" "2FRose" "3FOrchid" "3FJasmine" "4F";

DO i= 1 to 5;
IF FLOWER_ARRANGEMENT=REWRITE{1, i} THEN FLOWER_ARRANGEMENT=REWRITE{2, i};
END;
RUN;

6 REPLIES 6
Kurt_Bremser
Super User

Arrays are addressing mechanisms for variables, you can't have "variable-less" arrays. But you can define "temporary arrays". Google "sas temporary arrays" for further information.

Astounding
PROC Star

Try adding this word:

 

_temporary_

 

inside the array statement, just after the closing brackets.

 

ARRAY REWRITE{2, 5} _temporary_ "LilyOrchid" ............................;

a_ramos
Obsidian | Level 7

Thank you. It was good to discover that this is possible.

SuryaKiran
Meteorite | Level 14

Formatting might work for you.

 

proc format;
value $Gender
		'M'='Male'
		'F'='Female'
		other='UNK';
run;

data test;
set sashelp.class;
format sex $Gender.;
run;
Thanks,
Suryakiran
a_ramos
Obsidian | Level 7

Thank you. I'll choose the array because I'd rather not interrupt the dataset in what I'm doing

Reeza
Super User
Agreed with @SuryaKiran, this is a better use for PROC FORMAT than a temporary array though it's a perfectly valid option. A better method may be to use FINDW to find the word in a fixed list and then once you have the index, look it up in the temporary array. One less loop.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1277 views
  • 6 likes
  • 5 in conversation