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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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