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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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